Source code for ivy.container.container_methods

#ivy.container.activations
# local
import ivy
from ivy.container.base import ContainerBase
from typing import Optional, Union, List, Dict
# ToDo: implement all methods here as public instance methods
# noinspection PyMissingConstructor




[docs]def static_relu( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.relu. This method simply wraps the function, and so the docstring for ivy.relu also applies to this method with minimal changes. Parameters ---------- x input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the rectified linear activation unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([1.0, -1.2]), b=ivy.array([0.4, -0.2])) >>> y = ivy.Container.static_relu(x) >>> print(y) { a: ivy.array([1., 0.]), b: ivy.array([0.40000001, 0.]) } """ return ContainerBase.cont_multi_map_in_function( "relu", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def relu( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.relu. This method simply wraps the function, and so the docstring for ivy.relu also applies to this method with minimal changes. Parameters ---------- self input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the rectified linear activation unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([1.0, -1.2]), b=ivy.array([0.4, -0.2])) >>> y = x.relu() >>> print(y) { a: ivy.array([1., 0.]), b: ivy.array([0.40000001, 0.]) } """ return self.static_relu( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_leaky_relu( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, alpha: ivy.Container = 0.2, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.leaky_relu. This method simply wraps the function, and so the docstring for ivy.leaky_relu also applies to this method with minimal changes. Parameters ---------- x input container. alpha array or scalar specifying the negative slope. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the leaky relu unit function applied element-wise. Examples -------- >>> x = x = ivy.Container(a=ivy.array([0.39, -0.85]), b=ivy.array([1., -0.2])) >>> y = ivy.Container.static_leaky_relu(x) >>> print(y) { a: ivy.array([0.38999999, -0.17]), b: ivy.array([1., -0.04]) } """ return ContainerBase.cont_multi_map_in_function( "leaky_relu", x, alpha=alpha, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def leaky_relu( self: ivy.Container, /, *, alpha: ivy.Container = 0.2, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.leaky_relu. This method simply wraps the function, and so the docstring for ivy.leaky_relu also applies to this method with minimal changes. Parameters ---------- self input container. alpha array or scalar specifying the negative slope. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the leaky relu unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([0.39, -0.85]), b=ivy.array([1., -0.2])) >>> y = x.leaky_relu() >>> print(y) { a: ivy.array([0.38999999, -0.17]), b: ivy.array([1., -0.04]) } """ return self.static_leaky_relu( self, alpha=alpha, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_gelu( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, approximate: Optional[ivy.Container] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.gelu. This method simply wraps the function, and so the docstring for ivy.gelu also applies to this method with minimal changes. Parameters ---------- x input container. approximate whether to use the gelu approximation algorithm or exact formulation. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the gelu unit function applied element-wise. Examples -------- >>> x = ivy.Container(a =ivy.array([0.3, -0.1])) >>> y = ivy.Container.static_gelu(x) >>> print(y) { a: ivy.array([0.185, -0.046]) } """ return ContainerBase.cont_multi_map_in_function( "gelu", x, approximate=approximate, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def gelu( self: ivy.Container, /, *, approximate: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.gelu. This method simply wraps the function, and so the docstring for ivy.gelu also applies to this method with minimal changes. Parameters ---------- self input container. approximate whether to use the gelu approximation algorithm or exact formulation. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the gelu unit function applied element-wise. Examples -------- >>> x = ivy.Container(a =ivy.array([0.3, -0.1])) >>> y = x.gelu() >>> print(y) { a: ivy.array([0.185, -0.046]) } """ return self.static_gelu( self, approximate=approximate, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sigmoid( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sigmoid. This method simply wraps the function, and so the docstring for ivy.sigmoid also applies to this method with minimal changes. Parameters ---------- x input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the sigmoid unit function applied element-wise. Examples -------- >>> ivy.Container(a=ivy.array([-1., 1., 2.]), b=ivy.array([0.5, 0., -0.1])) >>> y = ivy.Container.static_sigmoid(x) >>> print(y) { a: ivy.array([0.2689414, 0.7310586, 0.88079703]), b: ivy.array([0.62245935, 0.5, 0.4750208]) } """ return ContainerBase.cont_multi_map_in_function( "sigmoid", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sigmoid( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sigmoid. This method simply wraps the function, and so the docstring for ivy.sigmoid also applies to this method with minimal changes. Parameters ---------- self input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the sigmoid unit function applied element-wise. Examples -------- >>> ivy.Container(a=ivy.array([-1., 1., 2.]), b=ivy.array([0.5, 0., -0.1])) >>> y = x.sigmoid() >>> print(y) { a: ivy.array([0.2689414, 0.7310586, 0.88079703]), b: ivy.array([0.62245935, 0.5, 0.4750208]) } """ return self.static_sigmoid( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_softmax( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: Optional[ivy.Container] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.softmax. This method simply wraps the function, and so the docstring for ivy.softmax also applies to this method with minimal changes. Parameters ---------- x input container. axis the axis or axes along which the softmax should be computed key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the softmax unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([1.0, 0]), b=ivy.array([1.3, 0, -1.0])) >>> y = ivy.Container.static_softmax(x) >>> print(y) { a: ivy.array([0.7310586, 0.2689414]), b: ivy.array([0.72844321, 0.19852395, 0.07303288]) } """ return ContainerBase.cont_multi_map_in_function( "softmax", x, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def softmax( self: ivy.Container, /, *, axis: Optional[ivy.Container] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.softmax. This method simply wraps the function, and so the docstring for ivy.softmax also applies to this method with minimal changes. Parameters ---------- self input container. axis the axis or axes along which the softmax should be computed key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the softmax unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([1.0, 0]), b=ivy.array([1.3, 0, -1.0])) >>> y = x.softmax() >>> print(y) { a: ivy.array([0.7310586, 0.2689414]), b: ivy.array([0.72844321, 0.19852395, 0.07303288]) } """ return self.static_softmax( self, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_softplus( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, beta: Optional[Union[int, float]] = None, threshold: Optional[Union[int, float]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.softplus. This method simply wraps the function, and so the docstring for ivy.softplus also applies to this method with minimal changes. Parameters ---------- x input container. beta The beta value for the softplus formation. Default: ``None``. threshold values above this revert to a linear function. Default: ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the softplus unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([-0.3461, -0.6491]), b=ivy.array([1., 0.])) >>> y = ivy.Container.static_softplus(x) >>> print(y) { a: ivy.array([0.53499615, 0.42036411]), b: ivy.array([1.31326175, 0.69314718]) } >>> x = ivy.Container(a=ivy.array([-1., 2., 4.])) >>> y = ivy.Container.static_softplus(x, beta=0.5, threshold=2) >>> print(y) { a: ivy.array([0.948, 2.63, 4.25]) } """ return ContainerBase.cont_multi_map_in_function( "softplus", x, beta=beta, threshold=threshold, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def softplus( self: ivy.Container, /, *, beta: Optional[Union[int, float]] = None, threshold: Optional[Union[int, float]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.softplus. This method simply wraps the function, and so the docstring for ivy.softplus also applies to this method with minimal changes. Parameters ---------- self input container. beta The beta value for the softplus formation. Default: ``None``. threshold values above this revert to a linear function. Default: ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the softplus unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([-0.3461, -0.6491])) >>> y = x.softplus() >>> print(y) { a: ivy.array([0.535, 0.42]) } >>> x = ivy.Container(a=ivy.array([-1., 2., 4.])) >>> y = x.softplus(beta=0.5, threshold=2) >>> print(y) { a: ivy.array([0.948, 2.63, 4.25]) } """ return self.static_softplus( self, beta=beta, threshold=threshold, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_log_softmax( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: Optional[ivy.Container] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.log_softmax. This method simply wraps the function, and so the docstring for ivy.log_softmax also applies to this method with minimal changes. Parameters ---------- x input container. axis the axis or axes along which the log_softmax should be computed key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the log_softmax unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([-1.0, -0.98, 2.3])) >>> y = ivy.Container.static_log_softmax(x) >>> print(y) { a: ivy.array([-3.37, -3.35, -0.0719]) } >>> x = ivy.Container(a=ivy.array([1.0, 2.4]), b=ivy.array([-0.2, -1.0])) >>> y = ivy.Container.static_log_softmax(x) >>> print(y) { a: ivy.array([-1.62, -0.22]), b: ivy.array([-0.371, -1.17]) } """ return ContainerBase.cont_multi_map_in_function( "log_softmax", x, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def log_softmax( self: ivy.Container, /, *, axis: Optional[ivy.Container] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ): """ ivy.Container instance method variant of ivy.log_softmax. This method simply wraps the function, and so the docstring for ivy.log_softmax also applies to this method with minimal changes. Parameters ---------- self input container. axis the axis or axes along which the log_softmax should be computed key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the log_softmax unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([-1.0, -0.98, 2.3])) >>> y = x.log_softmax() >>> print(y) { a: ivy.array([-3.37, -3.35, -0.0719]) } >>> x = ivy.Container(a=ivy.array([1.0, 2.4]), b=ivy.array([-0.2, -1.0])) >>> y = x.log_softmax() >>> print(y) { a: ivy.array([-1.62, -0.22]), b: ivy.array([-0.371, -1.17]) } """ return self.static_log_softmax( self, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_mish( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.mish. This method simply wraps the function, and so the docstring for ivy.mish also applies to this method with minimal changes. Parameters ---------- x input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the rectified linear activation unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([1.0, -1.2]), b=ivy.array([0.4, -0.2])) >>> y = ivy.Container.static_mish(x) >>> print(y) { a: ivy.array([0.86509842, -0.30883577]), b: ivy.array([0.28903052, -0.10714479]) } """ return ContainerBase.cont_multi_map_in_function( "mish", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def mish( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.mish. This method simply wraps the function, and so the docstring for ivy.mish also applies to this method with minimal changes. Parameters ---------- self input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the rectified linear activation unit function applied element-wise. Examples -------- >>> x = ivy.Container(a=ivy.array([1.0, -1.2]), b=ivy.array([0.4, -0.2])) >>> y = x.mish() >>> print(y) { a: ivy.array([0.86509842, -0.30883577]), b: ivy.array([0.28903052, -0.10714479]) } """ return self.static_mish( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.base """Base Container Object.""" # global import inspect from itertools import chain import re import abc import copy import termcolor import numpy as np import json from ivy.exceptions import IvyBackendException, IvyException try: # noinspection PyPackageRequirements import h5py except ModuleNotFoundError: h5py = None import pickle import random from operator import mul from functools import reduce from typing import Union, Tuple from builtins import set # local import ivy ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])") # noinspection PyMissingConstructor def _is_jsonable(x): try: json.dumps(x) return True except (TypeError, OverflowError): return False def _repr(x): try: return x.__repr__() except TypeError: return str(x) pass def __init__( self, dict_in=None, queues=None, queue_load_sizes=None, container_combine_method="list_join", queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color="green", keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, **kwargs, ): """Initialize container object from input dict representation. Parameters ---------- dict_in the dictionary the container should wrap around. Default is ``None``. queues Sequence of multiprocessing queues, each of which returns containers. This enables the current container to be passed around asynchronously while waiting for data. Default is ``None``. queue_load_sizes Size of leading dimension of the containers returned by each queue. Default is ``None``. container_combine_method The method to use for combining containers arriving from different queues. Default is ivy.Container.cont_list_join queue_timeout The timeout when waiting for containers to arrive from the queues. Default is global. print_limit The total array size limit when printing the container. Default is 10. key_length_limit The maximum key length when printing the container. Default is ``None``. print_indent The number of whitespaces to use for indenting when printing the container. Default is 4. print_line_spacing The number of extra newlines to use between keys when printing the container. Default is ``0``. ivyh Handle to ivy module to use for the calculations. Default is ``None``, which results in the global ivy. default_key_color The default key color for printing the container to the terminal. Default is 'green'. keyword_color_dict A dict mapping keywords to their termcolor color codes for printing the container. (Default value = None) rebuild_child_containers Whether to rebuild container found in dict_in with these constructor params. Default is ``False``, in which case the original container are kept as are. types_to_iteratively_nest The data types to nest iteratively in the dict structure, each type must be iterable. Default is ``None``. alphabetical_keys Whether to sort the container keys alphabetically, or preserve the dict order. Default is ``True``. kwargs keyword arguments for dict creation. Default is ``None``. """ self._queues = queues self._container_combine_method = container_combine_method if ivy.exists(self._queues): if isinstance(self._container_combine_method, str): self._container_combine_method = { "list_join": self.cont_list_join, "concat": lambda conts: self.concat(conts, 0), }[self._container_combine_method] self._loaded_containers_from_queues = dict() self._queue_load_sizes_cum = np.cumsum(queue_load_sizes) self._queue_timeout = ivy.default(queue_timeout, ivy.get_queue_timeout()) if dict_in is None: if kwargs: dict_in = dict(**kwargs) else: dict_in = dict() elif kwargs: raise ivy.exceptions.IvyException( "dict_in and **kwargs cannot both be specified for ivy.Container " "constructor, please specify one or the other, not both." ) self._config_in = dict( print_limit=print_limit, print_indent=print_indent, key_length_limit=key_length_limit, print_line_spacing=print_line_spacing, ivyh=ivyh, default_key_color=default_key_color, keyword_color_dict=keyword_color_dict, rebuild_child_containers=rebuild_child_containers, types_to_iteratively_nest=types_to_iteratively_nest, alphabetical_keys=alphabetical_keys, ) self._config = dict() self.cont_inplace_update(dict_in, **self._config_in) def cont_multi_map_in_function( fn, *args, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=None, out=None, **kwargs, ) -> Union[Tuple[ivy.Container, ivy.Container], ivy.Container]: inspect_fn = fn if isinstance(fn, str): inspect_fn = ivy.__dict__[fn] arg_cont_idxs = ivy.nested_argwhere( args, ivy.is_ivy_container, to_ignore=ivy.Container ) kwarg_cont_idxs = ivy.nested_argwhere( kwargs, ivy.is_ivy_container, to_ignore=ivy.Container ) # retrieve all the containers in args and kwargs arg_conts = ivy.multi_index_nest(args, arg_cont_idxs) num_arg_conts = len(arg_conts) kwarg_conts = ivy.multi_index_nest(kwargs, kwarg_cont_idxs) # Combine the retrieved containers from args and kwargs into a single list with_out = ( inspect.signature(inspect_fn).parameters.get("out") is not None and out is not None ) if with_out: conts = arg_conts + kwarg_conts + [out] else: conts = arg_conts + kwarg_conts ivy.assertions.check_exists(conts, message="no containers found in arguments") cont0 = conts[0] if isinstance(fn, str): fn = cont0.cont_ivy.__dict__[fn] # Get the function with the name fn_name, enabling containers to specify # their backends irrespective of global ivy's backend def map_fn(vals, _): if with_out: out = vals[-1] del vals[-1] arg_vals = vals[:num_arg_conts] a = ivy.copy_nest(args, to_mutable=True) ivy.set_nest_at_indices(a, arg_cont_idxs, arg_vals) kwarg_vals = vals[num_arg_conts:] kw = ivy.copy_nest(kwargs, to_mutable=True) ivy.set_nest_at_indices(kw, kwarg_cont_idxs, kwarg_vals) if with_out: return fn(*a, out=out, **kw) else: return fn(*a, **kw) # Replace each container in arg and kwarg with the arrays at the leaf # levels of that container using map_fn and call fn using those arrays # as inputs ret = ivy.Container.cont_multi_map( map_fn, conts, key_chains, to_apply, prune_unapplied, map_nests=map_sequences, ) if ivy.exists(out): out.inplace_update(ret) ret = out # Multiple containers for functions returning multiple arrays for values in ret.values(): if isinstance(values, list): for v in values: if ivy.is_ivy_array(v): return ret.cont_unstack_conts(0) return ret def cont_handle_inplace(ret, out): """Returns an inplace update of out, provided it is not None, by updating with the values in ret. Parameters ---------- ret The container with the return values out The optional out container, which is primed for being overwritten if it exists Returns ------- The out container, but filled with the values from the ret container """ if ivy.exists(out): out.inplace_update(ret) ret = out return ret def cont_list_join(containers, config=None): """Join containers of lists together along the specified dimension. Parameters ---------- containers containers to list join config The configuration for the containers. Default is the same as container0. Returns ------- List joined containers, with each entry being a list of arrays """ container0 = containers[0] if not ivy.exists(config): config = ( container0.cont_config if isinstance(container0, ivy.Container) else {} ) if isinstance(container0, ivy.Container): return_dict = dict() for key in container0.keys(): new_list = list() for container in containers: new_list.append(container[key]) return_dict[key] = ivy.Container.cont_list_join(new_list, config) return ivy.Container(return_dict, **config) else: return [item for sublist in containers for item in sublist] def cont_list_stack(containers, dim, config=None): """List stack containers together along the specified dimension. Parameters ---------- containers containers to list stack dim dimension along which to list stack config The configuration for the containers. Default is the same as container0. Returns ------- Stacked containers, with each entry being a list of arrays """ container0 = containers[0] if not ivy.exists(config): config = ( container0.cont_config if isinstance(container0, ivy.Container) else {} ) if isinstance(container0, ivy.Container): return_dict = dict() for key in container0.keys(): return_dict[key] = ivy.Container.cont_list_stack( [container[key] for container in containers], dim, config ) return ivy.Container(return_dict, **config) else: return containers def _cont_concat_unify(containers, device, axis=0): return ivy.concat( [cont.to_device(device) for cont in containers.values()], axis=axis ) def _cont_sum_unify(containers, device, _=None, _1=None): return sum( [cont.to_device(device) for cont in containers.values()], start=ivy.zeros([]), ) def _cont_mean_unify(containers, device, _=None, _1=None): return ivy.Container._cont_sum_unify(containers, device) / len(containers) def cont_unify(containers, device, mode, axis=0): """Unify a list of containers, on arbitrary devices, to a single container on the specified device. Parameters ---------- containers containers to unify dev The device to unify the containers to. mode The mode by which to unify, must be one of [ concat | mean | sum ] axis The axis along which to concattenate the container, if concat mode is set. Default is ``0``. Returns ------- Unified container """ return { "concat": ivy.Container._cont_concat_unify, "sum": ivy.Container._cont_sum_unify, "mean": ivy.Container._cont_mean_unify, }[mode](containers, device, axis) def cont_combine(*containers, config=None): """Combine keys and values in a sequence of containers, with priority given to the right-most container in the case of duplicates. Parameters ---------- containers containers to compare config The configuration for the containers. Default is the same as container_rightmost. Returns ------- Combined containers """ # if inputs are not dicts, then simply return the right-most value container_rightmost = containers[-1] if not isinstance(container_rightmost, dict): return container_rightmost if not ivy.exists(config): # noinspection PyUnresolvedReferences config = ( container_rightmost.cont_config if isinstance(container_rightmost, ivy.Container) else {} ) # return if len==1 if len(containers) == 1: return container_rightmost # otherwise, check that the keys are aligned between each container, and apply # this method recursively return_dict = dict() all_keys = set( [ item for sublist in [list(cont.keys()) for cont in containers] for item in sublist ] ) for key in all_keys: keys_present = [key in cont for cont in containers] return_dict[key] = ivy.Container.cont_combine( *[cont[key] for cont, kp in zip(containers, keys_present) if kp], config=config, ) return ivy.Container(return_dict, **config) def cont_diff( *containers, mode="all", diff_keys="diff", detect_key_diffs=True, detect_value_diffs=True, detect_shape_diffs=True, config=None, ): """Compare keys and values in a sequence of containers, returning the single shared values where they are the same, and new nested sub-dicts with all values where they are different. Parameters ---------- containers containers to compare mode The mode of the diff operation, returning either all keys and values, only those that are consist across the containers, or only the differences. Default is all. diff_keys The key/keys to add to the returned container when differences are found. Default is ``"diff"``. detect_key_diffs Whether to treat different keys as detected differences. If not, the keys among the input containers are simply combined without flagging differences. Default is ``True``. detect_value_diffs Whether to treat different values as detected differences. Default is ``True``. detect_shape_diffs Whether to treat different array shapes as detected differences. Default is ``True``. config The configuration for the containers. Default is the same as container0. *containers Returns ------- Compared containers """ ivy.assertions.check_elem_in_list(mode, ["all", "same_only", "diff_only"]) # if inputs are not dicts, then compare their values to determine the diff dict num_containers = len(containers) container0 = containers[0] if not ivy.exists(config): config = ( container0.cont_config if isinstance(container0, ivy.Container) else {} ) if not isinstance(container0, dict): equal_mat = ivy.all_equal(*containers, equality_matrix=True) if not detect_value_diffs: equal_mat = ivy.ones_like(equal_mat) if detect_shape_diffs: shape_equal_mat = ivy.all_equal( *[c.shape if ivy.is_array(c) else None for c in containers], equality_matrix=True, ) equal_mat = ivy.logical_and(equal_mat, shape_equal_mat) # noinspection PyTypeChecker if ivy.min(ivy.astype(equal_mat, "int32")) == 1: if mode == "diff_only": return ivy.Container(**config) return container0 elif mode == "same_only": return ivy.Container(**config) else: cont_range = range(num_containers) diff_dict = dict() cont_dict = dict(zip(cont_range, containers)) idxs_added = list() for idx in cont_range: if idx not in idxs_added: idxs_to_add = ivy.argwhere(equal_mat[idx]) idxs_to_add_list = sorted( ivy.to_numpy(idxs_to_add).reshape(-1).tolist() ) if isinstance(diff_keys, str): key = diff_keys + "_" + str(idxs_to_add_list)[1:-1] elif isinstance(diff_keys, (list, tuple)): key = diff_keys[idx] else: raise ivy.exceptions.IvyException( "diff_keys must be either a string or list of strings," "but found {} of type {}".format( diff_keys, type(diff_keys) ) ) diff_dict[key] = cont_dict[idx] idxs_added += idxs_to_add_list return ivy.Container(diff_dict, **config) # otherwise, check that the keys are aligned between each container, and apply # this method recursively return_dict = dict() all_keys = set( [ item for sublist in [list(cont.keys()) for cont in containers] for item in sublist ] ) for key in all_keys: keys_present = [key in cont for cont in containers] all_keys_present = sum(keys_present) == num_containers if all_keys_present: res = ivy.Container.cont_diff( *[cont[key] for cont in containers], mode=mode, diff_keys=diff_keys, detect_key_diffs=detect_key_diffs, detect_value_diffs=detect_value_diffs, detect_shape_diffs=detect_shape_diffs, config=config, ) if not isinstance(res, dict) or res: return_dict[key] = res continue elif sum(keys_present) == 1 and not detect_key_diffs: if mode == "all": return_dict[key] = containers[keys_present.index(True)][key] continue diff_dict = dict() for i, (key_present, cont) in enumerate(zip(keys_present, containers)): if detect_key_diffs: if key_present and mode != "same_only": if isinstance(diff_keys, str): diff_dict[diff_keys + "_" + str(i)] = cont[key] elif isinstance(diff_keys, (list, tuple)): diff_dict[diff_keys[i]] = cont[key] else: raise ivy.exceptions.IvyException( "diff_keys must be either a string or list of strings," "but found {} of type {}".format( diff_keys, type(diff_keys) ) ) if diff_dict: return_dict[key] = diff_dict return ivy.Container(return_dict, **config) def cont_structural_diff( *containers, mode="all", diff_keys="diff", detect_key_diffs=True, detect_shape_diffs=True, config=None, ): """Compare keys and shapes in a sequence of containers, returning the single shared values where they are the same, and new nested sub-dicts with all values where they are different. Parameters ---------- containers containers to compare mode The mode of the diff operation, returning either all keys and values, only those that are consist across the containers, or only the differences. Default is all. diff_keys The key/keys to add to the returned container when differences are found. Default is "diff". detect_key_diffs Whether to treat different keys as detected differences. If not, the keys among the input containers are simply combined without flagging differences. Default is ``True``. detect_shape_diffs Whether to treat different array shapes as detected differences. Default is ``True``. config The configuration for the containers. Default is the same as container0. *containers Returns ------- Compared containers """ return ivy.Container.cont_diff( *containers, mode=mode, diff_keys=diff_keys, detect_key_diffs=detect_key_diffs, detect_value_diffs=False, detect_shape_diffs=detect_shape_diffs, config=config, ) def cont_multi_map( func, containers, key_chains=None, to_apply=True, prune_unapplied=False, key_chain="", config=None, map_nests=False, assert_identical=False, ): """Apply function to all array values from a collection of identically structured containers. Parameters ---------- func Function to apply to each container entry. containers containers to map. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied, otherwise the leftmost container value is used. Default is ``False``. key_chain Chain of keys for this dict entry (Default value = '') config The configuration for the containers. Default is the same as container0. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. assert_identical Whether to assert that the input containers are identical or not. Returns ------- Container """ container0 = None for cont in containers: if isinstance(cont, ivy.Container): container0 = cont break ivy.assertions.check_exists( container0, message="No containers found in the inputs to ivy.Container.cont_multi_map", ) if not ivy.exists(config): config = ( container0.cont_config if isinstance(container0, ivy.Container) else {} ) return_dict = dict() for key in container0.keys(): values = [ cont[key] if isinstance(cont, ivy.Container) and key in cont else cont for cont in containers ] value0 = values[0] this_key_chain = key if key_chain == "" else (key_chain + "/" + key) is_container = [ivy.is_ivy_container(x) for x in values] def _found_in_key_chains(this_key_chain, key_chains): if key_chains is None: return False for key_chain in key_chains: if this_key_chain.startswith(key_chain): return True return False if not assert_identical and not all(is_container) and any(is_container): found = _found_in_key_chains(this_key_chain, key_chains) if key_chains is not None: if (found and not to_apply) or (not found and to_apply): if prune_unapplied: continue return_dict[key] = value0 continue return_dict[key] = func(values, this_key_chain) else: if isinstance(value0, ivy.Container): ret = ivy.Container.cont_multi_map( func, values, key_chains, to_apply, prune_unapplied, this_key_chain, config, map_nests, assert_identical, ) if ret: return_dict[key] = ret elif any(isinstance(x, (list, tuple)) for x in values) and map_nests: ret = ivy.nested_multi_map( lambda x, _: func(x, None), values, to_ivy=False ) if prune_unapplied and not ret: continue return_dict[key] = ret else: found = _found_in_key_chains(this_key_chain, key_chains) if key_chains is not None: if (found and not to_apply) or (not found and to_apply): if prune_unapplied: continue return_dict[key] = value0 continue return_dict[key] = func(values, this_key_chain) # noinspection PyProtectedMember return ivy.Container(return_dict, **config) def cont_common_key_chains(containers): """Return the key-chains common across all containers. Parameters ---------- containers Containers to check. Returns ------- list of key-chains. """ if len(containers) == 1: return containers[0].cont_all_key_chains() sets = [set(cont.cont_all_key_chains()) for cont in containers] return list(sets[0].intersection(*sets[1:])) def cont_identical( containers, check_types=True, check_shapes=True, same_arrays=True, arrays_equal=True, key_chains=None, to_apply=True, partial=False, key_chain="", ): """Returns a single boolean as to whether the input containers have identical key-chains and data types. Parameters ---------- containers containers to check. check_types Whether to check if the datatypes of the leaf nodes are the same. Default is ``True``. check_shapes Whether to check if the shapes of the leaf nodes are the same. Default is ``True``. same_arrays Whether to check if the arrays are the exact same instances. Default is ``True``. arrays_equal Whether to check if the arrays have equal values. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. partial Whether to also check for partially complete sub-containers. Default is ``False``. key_chain Chain of keys for this dict entry (Default value = '') Returns ------- Boolean """ if partial: common_key_chains = ivy.Container.cont_common_key_chains(containers) if not common_key_chains: return False containers = [ cont.cont_at_key_chains(common_key_chains) for cont in containers ] keys = set([i for sl in [list(cont.keys()) for cont in containers] for i in sl]) # noinspection PyProtectedMember for key in keys: if not min([key in cont for cont in containers]): return False values = [cont[key] for cont in containers] value_0 = values[0] type_0 = type(value_0) types = [type(val) for val in values] if not min([type_n is type_0 for type_n in types]): if isinstance(value_0, ivy.Container) or check_types: return False if ivy.is_array(value_0): if check_shapes: shape_0 = value_0.shape shapes = [val.shape for val in values] if not min([shape_n == shape_0 for shape_n in shapes]): return False if same_arrays: id_0 = id(value_0) ids = [id(val) for val in values] if not min([id_n == id_0 for id_n in ids]): return False elif arrays_equal: if not ivy.all_equal(*values): return False this_key_chain = key if key_chain == "" else (key_chain + "/" + key) if isinstance(value_0, ivy.Container): ret = ivy.Container.cont_identical( values, check_types, check_shapes, same_arrays, arrays_equal, key_chains, to_apply, partial, this_key_chain, ) if not ret: return False return True def cont_assert_identical( containers, check_types=True, check_shapes=True, same_arrays=True, arrays_equal=True, key_chains=None, to_apply=True, partial=False, ): """Assert whether the input containers are identical. Otherwise, the diff is shown in an exception. Parameters ---------- containers containers to check. check_types Whether to check if the datatypes of the leaf nodes are the same. Default is ``True``. check_shapes Whether to check if the shapes of the leaf nodes are the same. Default is ``True``. same_arrays Whether to check if the arrays are the exact same instances. Default is ``True``. arrays_equal Whether to check if the arrays have equal values. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. partial Whether to also check for partially complete sub-containers. Default is ``False``. """ ivy.assertions.check_true( ivy.Container.cont_identical( containers, check_types, check_shapes, same_arrays, arrays_equal, key_chains, to_apply, partial, ), "Containers were not identical:\n\n{}".format( ivy.Container.cont_diff(*containers) ), ) def cont_identical_structure( containers, check_types=True, check_shapes=True, key_chains=None, to_apply=True, partial=False, key_chain="", ): """Returns a single boolean as to whether the input containers have identical structure. Parameters ---------- containers containers to check. check_types Whether to also check whether the datatypes of the leaf nodes are the same. Default is ``True``. check_shapes Whether to also check whether the shapes of the leaf nodes are the same. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. partial Whether to also check for partially complete sub-containers. Default is ``False``. key_chain Chain of keys for this dict entry (Default value = '') Returns ------- Boolean """ return ivy.Container.cont_identical( containers, check_types, check_shapes, False, False, key_chains, to_apply, partial, key_chain, ) def cont_assert_identical_structure( containers, check_types=True, check_shapes=True, key_chains=None, to_apply=True, partial=False, ): """Assert whether the input containers have identical structure. Otherwise, the diff is shown in an exception. Parameters ---------- containers containers to check. check_types Whether to also check whether the datatypes of the leaf nodes are the same. Default is ``True``. check_shapes Whether to also check whether the shapes of the leaf nodes are the same. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. partial Whether to also check for partially complete sub-containers. Default is ``False``. """ ivy.assertions.check_true( ivy.Container.cont_identical_structure( containers, check_types, check_shapes, key_chains, to_apply, partial ), "Containers did not have identical structure:\n\n{}".format( ivy.Container.cont_structural_diff(*containers) ), ) def cont_identical_configs(containers): """Returns a single boolean as to whether the input containers all have identical configs. Parameters ---------- containers containers to check. """ ivy.assertions.check_greater(len(containers), 1) configs = [cont.cont_config for cont in containers] config0 = configs[0] for k, v in config0.items(): if not min([config[k] == v for config in configs]): return False return True def cont_identical_array_shapes(containers, exclusive=False): """Determine whether all of the containers have identical number of arrays and identical array shapes, regardless of their key-chain structures. Parameters ---------- containers containers to check. exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. (Default value = False) Returns ------- Boolean """ array_conts = [cont.cont_size_ordered_arrays(exclusive) for cont in containers] array_cont0 = array_conts[0] array_cont0_len = len(array_cont0) for array_cont in array_conts[1:]: if len(array_cont) != array_cont0_len: return False elif not min( [ a.shape == a0.shape for a, a0 in zip(array_cont.values(), array_cont0.values()) ] ): return False return True def cont_from_disk_as_hdf5( h5_obj_or_filepath, slice_obj=slice(None), alphabetical_keys=True, ivyh=None ): """Load container object from disk, as an h5py file, at the specified hdf5 filepath. Parameters ---------- h5_obj_or_filepath Filepath where the container object is saved to disk, or h5 object. slice_obj slice object to slice all h5 elements. (Default value = slice(None)) alphabetical_keys Whether to sort the container keys alphabetically, or preserve the dict order. Default is ``True``. ivyh Handle to ivy module to use for the calculations. Default is ``None``, which results in the global ivy. Returns ------- Container loaded from disk """ ivy.assertions.check_exists( h5py, message="You must install python package h5py in order to load hdf5 \ files from disk into a container.", ) container_dict = dict() if type(h5_obj_or_filepath) is str: h5_obj = h5py.File(h5_obj_or_filepath, "r") else: h5_obj = h5_obj_or_filepath items = sorted(h5_obj.items()) if alphabetical_keys else h5_obj.items() for key, value in items: if isinstance(value, h5py.Group): container_dict[key] = ivy.Container.cont_from_disk_as_hdf5( value, slice_obj, ivyh ) elif isinstance(value, h5py.Dataset): container_dict[key] = ivy.default(ivyh, ivy).array( list(value[slice_obj]) ) else: raise ivy.exceptions.IvyException( "Item found inside h5_obj which was neither a Group nor a Dataset." ) return ivy.Container(container_dict, ivyh=ivyh) def cont_from_disk_as_pickled(pickle_filepath, ivyh=None): """Load container object from disk at the specified pickle filepath. Parameters ---------- pickle_filepath Filepath where the container object is saved to disk. ivyh Handle to ivy module to use for the calculations. Default is ``None``, which results in the global ivy. Returns ------- Container loaded from disk """ return ivy.Container( pickle.load(open(pickle_filepath, "rb")), rebuild_child_containers=True, ivyh=ivyh, ).to_ivy() def cont_from_disk_as_json(json_filepath, ivyh=None): """Load container object from disk at the specified json filepath. If some objects were not json-able during saving, then they will be loaded as strings. Parameters ---------- json_filepath Filepath where the container object is saved to disk. ivyh Handle to ivy module to use for the calculations. Default is ``None``, which results in the global ivy. Returns ------- Container loaded from disk """ with open(json_filepath) as json_data_file: return ivy.Container(json.load(json_data_file), ivyh=ivyh) def h5_file_size(h5_obj_or_filepath): """Get file size of h5 file contents. Parameters ---------- h5_obj_or_filepath Filepath where the container object is saved to disk, or h5 object. Returns ------- Size of h5 file contents, and batch size. """ ivy.assertions.check_exists( h5py, message="You must install python package h5py in order to determine \ the size of hdf5 files.", ) if type(h5_obj_or_filepath) is str: h5_obj = h5py.File(h5_obj_or_filepath, "r") else: h5_obj = h5_obj_or_filepath size = 0 batch_size = 0 for key, value in h5_obj.items(): if isinstance(value, h5py.Group): size_to_add, batch_size = ivy.Container.h5_file_size(value) size += size_to_add elif isinstance(value, h5py.Dataset): value_shape = value.shape size += reduce(mul, value_shape, 1) * value.dtype.itemsize batch_size = value_shape[0] else: raise ivy.exceptions.IvyException( "Item found inside h5_obj which was neither a Group nor a Dataset." ) return size, batch_size def shuffle_h5_file(h5_obj_or_filepath, seed_value=0): """Shuffle entries in all datasets of h5 file, such that they are still aligned along axis 0. Parameters ---------- h5_obj_or_filepath Filepath where the container object is saved to disk, or h5 object. seed_value random seed to use for array shuffling (Default value = 0) """ ivy.assertions.check_exists( h5py, message="You must install python package h5py in order to shuffle \ hdf5 files on disk.", ) if seed_value is None: seed_value = random.randint(0, 1000) if type(h5_obj_or_filepath) is str: h5_obj = h5py.File(h5_obj_or_filepath, "a") else: h5_obj = h5_obj_or_filepath for key, value in h5_obj.items(): if isinstance(value, h5py.Group): ivy.Container.shuffle_h5_file(value, seed_value) elif isinstance(value, h5py.Dataset): random.seed(seed_value) # noinspection PyTypeChecker random.shuffle(value) else: raise ivy.exceptions.IvyException( "Item found inside h5_obj which was neither a Group nor a Dataset." ) if isinstance(h5_obj, h5py.File): h5_obj.close() def cont_reduce(containers, reduction, config=None): """Reduce containers. Parameters ---------- containers containers to reduce reduction the reduction function config The configuration for the containers. Default is the same as container0. Returns ------- reduced containers """ container0 = containers[0] if not ivy.exists(config): config = ( container0.cont_config if isinstance(container0, ivy.Container) else {} ) if isinstance(container0, ivy.Container): return_dict = dict() for key in container0.keys(): return_dict[key] = ivy.Container.cont_reduce( [container[key] for container in containers], reduction ) return ivy.Container(return_dict, **config) else: # noinspection PyBroadException try: return reduction(containers) except Exception as e: raise ivy.exceptions.IvyException( str(e) + "\nContainer reduce operation only valid for containers of arrays" ) def cont_flatten_key_chain( key_chain, replacement="__", above_height=None, below_depth=None ): """Summary. Parameters ---------- key_chain param replacement: (Default value = '__') above_height Default value = None) below_depth Default value = None) replacement (Default value = '__') """ # noinspection RegExpSingleCharAlternation flat_keys = re.split("/|\.", key_chain) num_keys = len(flat_keys) pre_keys = list() post_keys = list() if above_height and num_keys > above_height: post_keys = flat_keys[-above_height:] del flat_keys[-above_height:] if below_depth and num_keys > below_depth: pre_keys = flat_keys[0:below_depth] del flat_keys[0:below_depth] return "/".join( [ k for k in [ "/".join(pre_keys), replacement.join(flat_keys), "/".join(post_keys), ] if k ] ) def cont_trim_key(key, max_length): """Summary. Returns a trimmed key with a maximum length of max_length. Parameters ---------- key key to trim max_length maximum length of key """ key_len = len(key) if not ivy.exists(max_length) or key_len <= max_length: return key idxs = ( np.round( (key_len - 1) / (max_length - 1) * np.linspace(0, max_length - 1, max_length) ) .astype(np.int32) .tolist() ) return "".join([key[idx] for idx in idxs]) def _cont_call_static_method_with_flexible_args( self, static_method, *args, kw, required, defaults, self_idx=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=None, out=None, ) -> ivy.Container: if args: num_args = len(args) kw = { k: defaults[k] if k in defaults else v for i, (k, v) in enumerate(kw.items()) if i > num_args } args = list(args) if self_idx > num_args: k = list(kw.keys())[self_idx - num_args - 1] kw[k] = self else: args.insert(self_idx, self) return static_method( *args, **kw, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, ) self_set = False # set to leftmost non-specified required arg, if present for k in required: if kw[k] is None: kw[k] = self self_set = True break # go through each key and value of the keyword arguments for k, v in kw.items(): if v is None: if self_set: if k in defaults: # if self is set and a default value exists, set it kw[k] = defaults[k] else: # otherwise set self to this argument kw[k] = self self_set = True # call the static method return static_method( **kw, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, ) def _cont_get_shape(self): if not len(self.keys()): if ivy.exists(self._queues): return [self._queue_load_sizes_cum[-1]] return [0] sub_shapes = [ v for k, v in self.cont_map( lambda x, kc: list(x.shape) if self._cont_ivy.is_native_array(x) or isinstance(x, ivy.Array) else ([len(x)] if isinstance(x, (list, tuple)) else None) ).cont_to_iterator() if v ] if not sub_shapes: return sub_shapes min_num_dims = min([len(sub_shape) for sub_shape in sub_shapes]) sub_shapes_array = np.asarray( [sub_shape[0:min_num_dims] for sub_shape in sub_shapes] ) sub_shapes_array = np.where(sub_shapes_array == 0, -1, sub_shapes_array) mask = np.prod(sub_shapes_array / sub_shapes_array[0:1], 0) == 1 # noinspection PyTypeChecker return [ None if np.isnan(i) else int(i) for i in np.where( mask, sub_shapes_array[0], np.ones(min_num_dims) * float("nan") ).tolist() ] def _cont_get_shapes(self): return self.cont_map(lambda x, kc: x.shape if hasattr(x, "shape") else None) def _cont_get_dev(self, as_native=False): sub_devs = [ v for k, v in self.cont_map( lambda x, kc: self._cont_ivy.dev(x, as_native=as_native) if self._cont_ivy.is_native_array(x) or isinstance(x, ivy.Array) else None ).cont_to_iterator() if v ] if len(set(sub_devs)) <= 1: return sub_devs[0] return None def _cont_at_key_chains_input_as_seq(self, key_chains, ignore_key_errors=False): return_cont = ivy.Container(dict(), **self._config) for kc in key_chains: val = self.cont_at_key_chain(kc, ignore_key_errors=ignore_key_errors) if ignore_key_errors and not ivy.exists(val): continue return_cont.cont_set_at_key_chain(kc, val, inplace=True) return return_cont def _cont_at_key_chains_input_as_dict( self, key_chains, current_chain="", ignore_key_errors=False ): return_dict = dict() for k, v in key_chains.items(): if current_chain == "": new_current_chain = k else: new_current_chain = current_chain + "/" + k if isinstance(v, dict): return_dict[k] = self._cont_at_key_chains_input_as_dict( v, new_current_chain, ignore_key_errors=ignore_key_errors ) else: val = self.cont_at_key_chain( new_current_chain, ignore_key_errors=ignore_key_errors ) if ignore_key_errors and not ivy.exists(val): continue return_dict[k] = val return ivy.Container(return_dict, **self._config) def _cont_prune_key_chains_input_as_seq(self, key_chains): return_cont = self.cont_copy() for kc in key_chains: return_cont = return_cont.cont_prune_key_chain(kc) return return_cont def _cont_prune_key_chains_input_as_dict(self, key_chains, return_cont=None): if return_cont is None: return_cont = self.cont_copy() for k, v in key_chains.items(): if isinstance(v, dict): ret_cont = self._cont_prune_key_chains_input_as_dict(v, return_cont[k]) if ret_cont.shape[0] == 0: del return_cont[k] else: del return_cont[k] return return_cont def cont_duplicate_array_keychains(self): duplciates = () key_chains = self.cont_all_key_chains() skips = set() for i in range(len(key_chains)): temp_duplicates = () if key_chains[i] in skips: continue for j in range(i + 1, len(key_chains)): if key_chains[j] in skips: continue if self[key_chains[i]] is self[key_chains[j]]: if key_chains[i] not in temp_duplicates: temp_duplicates += (key_chains[i],) if key_chains[j] not in temp_duplicates: temp_duplicates += (key_chains[j],) if len(temp_duplicates) > 0: duplciates += (temp_duplicates,) skips = chain.from_iterable(duplciates) return duplciates def cont_update_config(self, **config): new_config = dict() for k, v in config.items(): att_name = "_" + k if k in self._config_in: if k == "types_to_iteratively_nest": v = ivy.default(lambda: tuple(v), (), catch_exceptions=True) elif k == "keyword_color_dict": v = ivy.default(v, {}) elif k == "ivyh": att_name = "_local_ivy" new_config[k] = v self.__setattr__(att_name, v) self._config = new_config def cont_inplace_update( self, dict_in: Union[ivy.Container, dict], **config ) -> ivy.Container: """Update the contents of this container inplace, using either a new dict or container. Parameters ---------- dict_in New dict or container to update the current container inplace with. **config """ # update config self.cont_update_config(**config) # update container values inplace if dict_in is None: return dict_types = tuple([dict] + ivy.container_types()) if isinstance(dict_in, dict_types): dict_in = dict_in elif isinstance(dict_in, tuple(self._types_to_iteratively_nest)): dict_in = dict( zip( [ "it_{}".format(str(i).zfill(len(str(len(dict_in))))) for i in range(len(dict_in)) ], dict_in, ) ) else: raise ivy.exceptions.IvyException("invalid input {}".format(dict_in)) items = sorted(dict_in.items()) if self._alphabetical_keys else dict_in.items() for key, value in items: if ( isinstance(value, dict_types) and ( not isinstance(value, ivy.Container) or self._rebuild_child_containers ) ) or isinstance(value, tuple(self._types_to_iteratively_nest)): self[key] = ivy.Container(value, **self._config) else: if key in self and isinstance(self[key], ivy.Container): self[key].cont_inplace_update(value) else: self[key] = value def cont_all_true( self, assert_is_bool=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, ): """Determine whether all the entries in the container boolean evaluate to True. Parameters ---------- assert_is_bool Whether or not to assert each entry is of type Boolean. (Default value = False) key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- Boolean, whether all entries are boolean True. """ return bool( np.prod( [ v for k, v in self.cont_as_bools( assert_is_bool, key_chains, to_apply, prune_unapplied, map_sequences, ).cont_to_iterator() ] ) ) def cont_all_false( self, assert_is_bool=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, ): """Determine whether all the entries in the container boolean evaluate to False. Parameters ---------- assert_is_bool Whether or not to assert each entry is of type Boolean. (Default value = False) key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- Boolean, whether all entries are boolean False. """ return not bool( np.sum( [ v for k, v in self.cont_as_bools( assert_is_bool, key_chains, to_apply, prune_unapplied, map_sequences, ).cont_to_iterator() ] ) ) def cont_slice_via_key(self, slice_key): """Get slice of container, based on key. Parameters ---------- slice_key key to slice container at. Returns ------- Container object sliced at desired key. """ return_dict = dict() for key, value in self.items(): if key == slice_key: return value elif isinstance(value, ivy.Container): return_dict[key] = value.cont_slice_via_key(slice_key) else: return_dict[key] = value return ivy.Container(return_dict, **self._config) def cont_as_bools( self, assert_is_bool=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, ): """Return boolean evaluation for all nested items in the container. Parameters ---------- assert_is_bool Whether or not to assert the entry is of type Boolean. (Default value = False) key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- Container object with all entries boolean evaluated. """ def _ret_bool(x): if assert_is_bool: ivy.assertions.check_isinstance(x, bool) return x return bool(x) return self.cont_map( lambda x, kc: _ret_bool(x), key_chains, to_apply, prune_unapplied, map_sequences, ) def cont_unstack_conts(self, axis, keepdims=False, dim_size=None): """Unstack containers along specified dimension. Parameters ---------- axis Dimensions along which to unstack. keepdims Whether to keep dimension 1 in the unstack dimensions. Default is ``False``. dim_size Size of the dimension to unstack. Determined from inputs by default. Returns ------- List of containers, unstacked along the specified dimension. """ if dim_size is None: dim_size = self.cont_shape[axis] if keepdims: # noinspection PyTypeChecker return [ self[ slice(i, i + 1, 1) if axis == 0 else tuple([slice(None, None, None)] * axis + [slice(i, i + 1, 1)]) ] for i in range(dim_size) ] # noinspection PyTypeChecker return [ self[i if axis == 0 else tuple([slice(None, None, None)] * axis + [i])] for i in range(dim_size) ] def split_conts( self, num_or_size_splits=None, axis=0, with_remainder=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, ): """Splits a container into multiple sub-containers, by splitting their constituent arrays. Parameters ---------- num_or_size_splits Number of equal arrays to divide the array into along the given axis if an integer. The size of each split element if a sequence of integers. Default is to divide into as many 1-dimensional arrays as the axis dimension. axis The axis along which to split, default is ``0``. with_remainder If the tensor does not split evenly, then store the last remainder entry. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- A list of sub-arrays. """ dim_size = ( num_or_size_splits if isinstance(num_or_size_splits, int) else len(num_or_size_splits) ) # noinspection PyTypeChecker return self.cont_map( lambda x, kc: self._cont_ivy.split( x, num_or_size_splits=num_or_size_splits, axis=axis, with_remainder=with_remainder, ) if self._cont_ivy.is_native_array(x) or isinstance(x, ivy.Array) else x, key_chains, to_apply, prune_unapplied, map_sequences, ).cont_unstack_conts(0, dim_size=dim_size) def cont_num_arrays(self, exclusive=False): """Compute the number of arrays present at the leaf nodes, including variables by default. Parameters ---------- exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. (Default value = False) """ return sum( self.cont_map( lambda x, kc: ivy.is_array(x, exclusive=exclusive) ).cont_to_iterator_values() ) def cont_size_ordered_arrays(self, exclusive=False): """Return a container with keychains mapped to flat keys, and arrays given in order of smallest to largest. Parameters ---------- exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. (Default value = False) """ array_dict = { ivy.Container.cont_flatten_key_chain(kc): v for kc, v in self.cont_to_iterator() if ivy.is_array(v, exclusive=exclusive) } return ivy.Container( dict( sorted( array_dict.items(), key=lambda item: reduce(mul, item[1].shape, 1) ) ), alphabetical_keys=False, ) def cont_to_disk_as_hdf5( self, h5_obj_or_filepath, starting_index=0, mode="a", max_batch_size=None ): """Save container object to disk, as an h5py file, at the specified filepath. Parameters ---------- h5_obj_or_filepath Filepath for where to save the container to disk, or h5 object. starting_index Batch index for which to start writing to file, if it already exists (Default value = 0) mode H5 read/write mode for writing to disk, ['r', 'r+', 'w', 'w-', 'a'], default is 'a'. max_batch_size Maximum batch size for the container on disk, this is useful if later appending to file. (Default value = None) """ ivy.assertions.check_exists( h5py, message="You must install python package h5py in order to save \ containers to disk as hdf5 files.", ) if type(h5_obj_or_filepath) is str: h5_obj = h5py.File(h5_obj_or_filepath, mode) else: h5_obj = h5_obj_or_filepath for key, value in self.items(): if isinstance(value, ivy.Container): if key not in h5_obj.keys(): h5_group = h5_obj.create_group(key) else: h5_group = h5_obj[key] value.cont_to_disk_as_hdf5( h5_group, starting_index, mode, max_batch_size ) else: value_as_np = self._cont_ivy.to_numpy(value) value_shape = value_as_np.shape this_batch_size = value_shape[0] if not max_batch_size: max_batch_size = starting_index + this_batch_size if key not in h5_obj.keys(): dataset_shape = [max_batch_size] + list(value_shape[1:]) maxshape = [None for _ in dataset_shape] h5_obj.create_dataset( key, dataset_shape, dtype=value_as_np.dtype, maxshape=maxshape ) space_left = max_batch_size - starting_index amount_to_write = min(this_batch_size, space_left) h5_obj[key][ starting_index : starting_index + amount_to_write ] = value_as_np[0:amount_to_write] def cont_to_disk_as_pickled(self, pickle_filepath): """Save container object to disk, as an pickled file, at the specified filepath. Parameters ---------- pickle_filepath Filepath for where to save the container to disk. """ pickle.dump(self.to_native().cont_to_dict(), open(pickle_filepath, "wb")) def cont_to_jsonable(self, return_dict=None): """ Parameters ---------- return_dict Default value = None) """ if return_dict is None: return_dict = self.cont_copy() for k, v in return_dict.items(): if not _is_jsonable(v): if isinstance(v, dict): return_dict[k] = self.cont_to_jsonable(v) else: return_dict[k] = str(v) return return_dict def cont_to_disk_as_json(self, json_filepath): """Save container object to disk, as an json file, at the specified filepath. Parameters ---------- json_filepath Filepath for where to save the container to disk. """ with open(json_filepath, "w+") as json_data_file: json.dump(self.cont_to_jsonable().cont_to_dict(), json_data_file, indent=4) def cont_to_nested_list(self): return_list = list() for key, value in self.items(): if isinstance(value, ivy.Container): return_list.append(value.cont_to_nested_list()) elif value is not None and key != "_f": return_list.append(value) return return_list def cont_to_raw(self): """Constructor to their original form. Returns ------- ret Container data in its raw form. """ return_item = dict() for i, (key, value) in enumerate(self.items()): if isinstance(value, ivy.Container): return_item[key] = value.cont_to_raw() elif key[0:3] == "it_" and tuple(self._types_to_iteratively_nest): return_item = list( [ v.cont_to_raw() if isinstance(v, ivy.Container) else v for v in self.values() ] ) break else: return_item[key] = value return return_item def cont_to_dict(self): """Summary. Returns ------- ret Container as nested dict. """ return_dict = dict() for key, value in self.items(): if isinstance(value, ivy.Container): return_dict[key] = value.cont_to_dict() else: return_dict[key] = value return return_dict def cont_to_iterator(self, key_chain="", leaf_keys_only=False, include_empty=False): """ Parameters ---------- key_chain Default value = '') leaf_keys_only Default value = False) include_empty Default value = False) Returns ------- Iterator for the container elements. """ for key, value in self.items(): if leaf_keys_only: kc = key else: kc = key_chain + "/" + key if key_chain != "" else key if isinstance(value, ivy.Container) and (not include_empty or value): yield from value.cont_to_iterator(kc, leaf_keys_only, include_empty) else: yield kc, value def cont_to_iterator_values(self, include_empty=False): """ Parameters ---------- include_empty Default value = False) Returns ------- Iterator for the container values. """ for key, value in self.items(): if isinstance(value, ivy.Container) and (not include_empty or value): # noinspection PyCompatibility yield from value.cont_to_iterator_values(include_empty) else: yield value def cont_to_iterator_keys( self, key_chain="", leaf_keys_only=False, include_empty=False ): """ Parameters ---------- key_chain Default value = '') leaf_keys_only Default value = False) include_empty Default value = False) Returns ------- Iterator for the container elements. """ for key, value in self.items(): if leaf_keys_only: kc = key else: kc = key_chain + "/" + key if key_chain != "" else key if isinstance(value, ivy.Container) and (not include_empty or value): # noinspection PyCompatibility yield from value.cont_to_iterator_keys( kc, leaf_keys_only, include_empty ) else: yield kc def cont_to_flat_list(self): """Summary. Returns ------- ret Container as flat list. """ return list([item for key, item in self.cont_to_iterator()]) def cont_from_flat_list(self, flat_list): """Return new container object with the same hierarchy, but with values replaced from flat list. Parameters ---------- flat_list flat list of values to populate container with. Returns ------- Container. """ new_dict = dict() for key, value in self.items(): if isinstance(value, ivy.Container): new_value = value.cont_from_flat_list(flat_list) else: new_value = flat_list.pop(0) new_dict[key] = new_value return ivy.Container(new_dict, **self._config) def cont_has_key(self, query_key): """Determine whether container object has specified key somewhere in the nested structure. Parameters ---------- query_key Returns ------- ret Boolean """ has_key = False def map_fn(x, kc): """ Parameters ---------- x param kc: kc """ nonlocal has_key if query_key in kc: has_key = True return x self.cont_map(map_fn) return has_key def cont_has_key_chain(self, key_chain): """Determine whether container object has specified key-chain. Parameters ---------- key_chain Returns ------- ret Boolean """ keys = re.split("[/.]", key_chain) ret = self for key in keys: try: ret = ret[key] except KeyError: return False return True def cont_find_sub_container(self, sub_cont_to_find, partial=False): """Find the sub-container in the current container if it exsits. Parameters ---------- sub_cont_to_find The sub-container to find. partial Whether to also check for partially complete sub-containers. Default is ``False``. """ key_chain_found = False def _check_sub_cont(sub_cont, kc): sub_cont_key_chains = sub_cont_to_find.cont_all_key_chains() kcs_in_sub_cont = [kc in sub_cont for kc in sub_cont_key_chains] if ( kcs_in_sub_cont and min(kcs_in_sub_cont) and ivy.Container.cont_identical( [sub_cont, sub_cont_to_find], partial=partial ) ): nonlocal key_chain_found key_chain_found = kc return sub_cont self.cont_map_sub_conts(_check_sub_cont) return key_chain_found def cont_contains_sub_container(self, sub_cont, partial=False): """Determine whether the current container contains the sub-container, with matching structure and array values. Parameters ---------- sub_cont The sub-container to check. partial Whether to also check for partially complete sub-containers. Default is ``False``. Returns ------- Bool """ return ( True if isinstance(self.cont_find_sub_container(sub_cont, partial), str) else False ) def cont_assert_contains_sub_container(self, sub_cont, partial=False): """Asserts that the current container contains the sub-container, otherwise exception raised with the diff printed to screen. Parameters ---------- sub_cont The sub-container to check. partial Whether to also check for partially complete sub-containers. Default is ``False``. """ try: ivy.assertions.check_true( self.cont_contains_sub_container(sub_cont, partial) ) except ivy.exceptions.IvyException: key_chain = self.cont_find_sub_structure( sub_cont, check_shapes=False, partial=True ) if not key_chain: key_chain = "" # noinspection PyTypeChecker raise ivy.exceptions.IvyException( "Containers did not have identical structure and values:\n\n{}".format( ivy.Container.cont_diff(self[key_chain], sub_cont) ) ) def cont_find_sub_structure( self, sub_struc_to_find, check_shapes=True, partial=False ): """Find the sub-container structure in the current container if it exsits. Parameters ---------- sub_struc_to_find The sub-container to find. check_shapes Whether to check array shapes in the sub-structure. Default is ``True``. partial Whether to also check for partially complete sub-containers. Default is ``False``. """ key_chain_found = False def _check_sub_cont(sub_cont, kc): """ Parameters ---------- sub_cont param kc: kc """ sub_struc_key_chains = sub_struc_to_find.cont_all_key_chains() kcs_in_sub_cont = [kc in sub_cont for kc in sub_struc_key_chains] if ( kcs_in_sub_cont and min(kcs_in_sub_cont) and ivy.Container.cont_identical_structure( [sub_cont, sub_struc_to_find], check_shapes=check_shapes, partial=partial, ) ): nonlocal key_chain_found key_chain_found = kc return sub_cont self.cont_map_sub_conts(_check_sub_cont) return key_chain_found def cont_contains_sub_structure(self, sub_cont, check_shapes=True, partial=False): """Determine whether the current container contains the sub-container structure. Parameters ---------- sub_cont The sub-container to check. check_shapes Whether to check array shapes in the sub-structure. Default is ``True``. partial Whether to also check for partially complete sub-containers. Default is ``False``. """ return ( True if isinstance( self.cont_find_sub_structure(sub_cont, check_shapes, partial), str ) else False ) def cont_assert_contains_sub_structure( self, sub_cont, check_shapes=True, partial=False ): """Asserts that the current container contains the sub-container structure, otherwise exception raised with the diff printed to screen. Parameters ---------- sub_cont The sub-container to check. check_shapes Whether to check array shapes in the sub-structure. Default is ``True``. partial Whether to also check for partially complete sub-containers. Default is ``False``. """ try: ivy.assertions.check_true( self.cont_contains_sub_structure(sub_cont, check_shapes, partial) ) except ivy.exceptions.IvyException: key_chain = self.cont_find_sub_structure( sub_cont, check_shapes=False, partial=True ) if not key_chain: key_chain = "" # noinspection PyTypeChecker raise ivy.exceptions.IvyException( "Containers did not have identical structure:\n\n{}".format( ivy.Container.cont_structural_diff( self[key_chain], sub_cont, detect_key_diffs=not partial, detect_shape_diffs=check_shapes, mode="diff_only" if partial else "all", ) ) ) def cont_at_keys( self, queries, ignore_none=True, containing=False, ignore_key_errors=False ): """Query container object at specified keys, either as list or nested dict. Parameters ---------- queries The keys to query. ignore_none Whether to ignore None input. Default is ``True``. containing Whether to include keys which only contain the query substrings. Default is ``False``. ignore_key_errors Whether to ignore Key-errors when trying to access the dict. Default is ``False``. Returns ------- sub-container containing only key-chains containing the specified keys. """ if queries is None and ignore_none: return self key_chains_to_keep = list() if isinstance(queries, str): queries = [queries] def map_fn(x, kc): nonlocal key_chains_to_keep kc_split = re.split("[/.]", kc) for query_key in queries: if query_key in kc_split or ( containing and min([query_key in k for k in kc_split]) ): key_chains_to_keep.append(kc) return x self.cont_map(map_fn) return self.cont_at_key_chains( key_chains_to_keep, ignore_key_errors=ignore_key_errors ) def cont_at_key_chain(self, key_chain, ignore_key_errors=False): """Query container object at a specified key-chain. Parameters ---------- key_chain param ignore_key_errors: (Default value = False) ignore_key_errors (Default value = False) Returns ------- ret sub-container or value at specified key chain """ keys = re.split("[/.]", key_chain) ret = self for key in keys: try: ret = ret[key] except KeyError as e: if ignore_key_errors: return raise ivy.exceptions.IvyException(repr(e)) return ret def cont_at_key_chains(self, key_chains, ignore_none=True, ignore_key_errors=False): """Query container object at specified key-chains, either as list or nested dict. Parameters ---------- key_chains param ignore_none: (Default value = True) ignore_key_errors Default value = False) ignore_none (Default value = True) Returns ------- type sub-container containing only the specified key chains """ if key_chains is None and ignore_none: return self if isinstance(key_chains, (list, tuple)): return self._cont_at_key_chains_input_as_seq( key_chains, ignore_key_errors=ignore_key_errors ) elif isinstance(key_chains, dict): return self._cont_at_key_chains_input_as_dict( key_chains, ignore_key_errors=ignore_key_errors ) elif isinstance(key_chains, str): return self._cont_at_key_chains_input_as_seq( [key_chains], ignore_key_errors=ignore_key_errors ) else: raise ivy.exceptions.IvyException( "Invalid type for input key_chains, must either be a list, tuple, dict" " or ivy.Container, but found type {}".format(type(key_chains)) ) def cont_all_key_chains(self, include_empty=False): """ Parameters ---------- include_empty Default value = False) """ return [kc for kc, v in self.cont_to_iterator(include_empty=include_empty)] def cont_key_chains_containing(self, sub_str, include_empty=False): """ Parameters ---------- sub_str param include_empty: (Default value = False) include_empty (Default value = False) """ return [ kc for kc, v in self.cont_to_iterator(include_empty=include_empty) if sub_str in kc ] def cont_set_at_keys(self, target_dict): """Set values of container object at specified keys. Parameters ---------- target_dict Returns ------- type new container with updated value at each key """ return_dict = dict() for key, val in self.items(): if key in target_dict: return_dict[key] = target_dict[key] elif isinstance(val, ivy.Container): return_dict[key] = val.cont_set_at_keys(target_dict) else: return_dict[key] = val return ivy.Container(return_dict, **self._config) def cont_set_at_key_chain(self, key_chain, val, inplace=False): """Set value of container object at a specified key-chain. Parameters ---------- key_chain param val: inplace Default value = False) val Returns ------- ret new container with updated value at key chain """ keys = re.split("[/.]", key_chain) if inplace: cont = self else: cont = self.cont_copy() sub_cont = cont for key in keys[:-1]: if key not in sub_cont: sub_cont[key] = ivy.Container(**self._config) sub_cont = sub_cont[key] sub_cont[keys[-1]] = val return cont def cont_overwrite_at_key_chain(self, key_chain, val, inplace=False): """Overwrite value of container object at a specified key-chain. Parameters ---------- key_chain param val: inplace Default value = False) val Returns ------- ret new container with updated value at key chain, provided it existed before. """ keys = re.split("[/.]", key_chain) if inplace: cont = self else: cont = self.cont_copy() sub_cont = cont for key in keys[:-1]: ivy.assertions.check_elem_in_list( key, sub_cont, message="key chain must already exist in container in order to \ call cont_overwrite_at_key_chain", ) sub_cont = sub_cont[key] ivy.assertions.check_elem_in_list( keys[-1], sub_cont, message="key chain must already exist in container in order to \ call cont_overwrite_at_key_chain", ) sub_cont[keys[-1]] = val return cont def cont_set_at_key_chains(self, target_dict, return_dict=None, inplace=False): """Set values of container object at specified key-chains. Parameters ---------- target_dict param return_dict: (Default value = None) inplace Default value = False) return_dict (Default value = None) Returns ------- ret new container with updated values at the key chains """ if return_dict is None: if inplace: return_dict = self else: return_dict = self.cont_copy() for k, v in target_dict.items(): if isinstance(v, dict): return_dict[k] = self.cont_set_at_key_chains(v, return_dict[k], inplace) else: return_dict[k] = v return ivy.Container(return_dict, **self._config) def cont_overwrite_at_key_chains( self, target_dict, return_dict=None, inplace=False ): """Overwrite values of container object at specified key-chains. Parameters ---------- target_dict param return_dict: (Default value = None) inplace Default value = False) return_dict (Default value = None) Returns ------- ret new container with updated values at the key chains, provided they existed before. """ if return_dict is None: if inplace: return_dict = self else: return_dict = self.cont_copy() for k, v in target_dict.items(): ivy.assertions.check_elem_in_list( k, return_dict, message="key chain must already exist in container in order to \ call cont_overwrite_at_key_chain", ) if isinstance(v, dict): return_dict[k] = self.cont_overwrite_at_key_chains( v, return_dict[k], inplace ) else: return_dict[k] = v return ivy.Container(return_dict, **self._config) def cont_prune_keys(self, query_keys, ignore_none=True): """Recursively prune set of keys. Parameters ---------- query_keys param ignore_none: (Default value = True) ignore_none (Default value = True) Returns ------- ret Container with key-chains containing the specified keys pruned. """ if query_keys is None and ignore_none: return self key_chains_to_prune = list() if isinstance(query_keys, str): query_keys = [query_keys] def map_fn(x, kc): """ Parameters ---------- x param kc: kc """ nonlocal key_chains_to_prune for query_key in query_keys: if query_key in kc: key_chains_to_prune.append(kc) return x self.cont_map(map_fn) return self.cont_prune_key_chains(key_chains_to_prune) def cont_prune_key_chain(self, key_chain): """Recursively prune chain of keys, specified as 'key1/key2/key3/...'. Parameters ---------- key_chain Returns ------- ret Container with keys in key chain pruned. """ keys_in_chain = re.split("[/.]", key_chain) out_dict = dict() for key, value in self.items(): if isinstance(value, ivy.Container): if key == keys_in_chain[0]: if len(keys_in_chain) == 1: new_val = [] else: new_val = value.cont_prune_key_chain( "/".join(keys_in_chain[1:]) ) if len(new_val) > 0: out_dict[key] = new_val else: new_val = value.cont_to_dict() if len(new_val) > 0: out_dict[key] = value.cont_to_dict() else: if len(keys_in_chain) != 1 or key != keys_in_chain[0]: out_dict[key] = value return ivy.Container(out_dict, **self._config) def cont_prune_key_chains(self, key_chains, ignore_none=True): """Recursively prune set of key chains. Parameters ---------- key_chains param ignore_none: (Default value = True) ignore_none (Default value = True) Returns ------- ret Container with keys in the set of key chains pruned. """ if key_chains is None and ignore_none: return self if isinstance(key_chains, (list, tuple)): return self._cont_prune_key_chains_input_as_seq(key_chains) elif isinstance(key_chains, dict): return self._cont_prune_key_chains_input_as_dict(key_chains) elif isinstance(key_chains, str): return self._cont_prune_key_chains_input_as_seq([key_chains]) else: raise ivy.exceptions.IvyException( "Invalid type for input key_chains, must either be a list, tuple, dict " "or ivy.Container, but found type {}".format(type(key_chains)) ) def cont_format_key_chains(self, format_fn): """Format all key-chains, using the formatting function. Parameters ---------- format_fn Returns ------- ret Container with the same key-chain structure, but the key strings formatted. """ return ivy.Container({format_fn(k): v for k, v in self.cont_to_iterator()}) def cont_sort_by_key(self): new_dict = dict() for k, v in self.items(): if isinstance(v, ivy.Container): v_back = v.cont_sort_by_key() else: v_back = v new_dict[k] = v_back return ivy.Container(new_dict, **self._config) def cont_prune_empty(self, keep_nones=False, base=True): """Recursively prunes empty keys from the container dict structure. Returns None if the entire container is empty. Parameters ---------- keep_nones Default value = False) base Default value = True) Returns ------- ret Container with empty keys pruned. """ out_dict = dict() for key, value in self.items(): if isinstance(value, ivy.Container): new_value = value.cont_prune_empty(keep_nones, False) if new_value: out_dict[key] = new_value elif self._cont_ivy.exists(value) or keep_nones: out_dict[key] = value if len(out_dict): return ivy.Container(out_dict, **self._config) if base: return ivy.Container(**self._config) return def cont_prune_key_from_key_chains(self, absolute=None, containing=None): """Recursively prune absolute key or key containing a certain substring from all key chains. Parameters ---------- absolute The absolute key to detect in the key chains. (Default value = None) containing A substring to check each key for, when deciding which keys to prune. (Default value = None) Returns ------- Container with specified key or substring-containing-key from all key chains removed from the chain. """ ivy.assertions.check_all_or_any_fn( absolute, containing, fn=ivy.exists, type="any", limit=[1, 2], message="at least one of absolute or containing must be specified", ) out_cont = ivy.Container(**self._config) for key, value in self.items(): if (absolute and key == absolute) or (containing and containing in key): if isinstance(value, ivy.Container): out_cont = ivy.Container.cont_combine(out_cont, value) else: out_cont = value elif isinstance(value, ivy.Container): out_cont[key] = value.cont_prune_key_from_key_chains( absolute, containing ) else: out_cont[key] = value return out_cont def cont_prune_keys_from_key_chains(self, absolute=None, containing=None): """Recursively prune absolute keys or keys containing certain substrings from all key chains. Parameters ---------- absolute The absolute key to detect in the key chains. (Default value = None) containing A substring to check each key for, when deciding which keys to prune. (Default value = None) Returns ------- Container with specified keys or substring-containing-keys from all key chains removed from the chain. """ ivy.assertions.check_all_or_any_fn( absolute, containing, fn=ivy.exists, type="any", limit=[1, 2], message="at least one of absolute or containing must be specified", ) out_cont = ivy.Container(**self._config) for key, value in self.items(): if (absolute and key in absolute) or ( containing and max([con in key for con in containing]) ): if isinstance(value, ivy.Container): out_cont = ivy.Container.cont_combine(out_cont, value) else: out_cont = value elif isinstance(value, ivy.Container): out_cont[key] = value.cont_prune_key_from_key_chains( absolute, containing ) else: out_cont[key] = value return out_cont def cont_restructure_key_chains( self, keychain_mapping, keep_orig=True, replace=True ): """Create a new container with the same contents, but a new key-chain structure. Given by the mapping with keys as old key-chains and values as new key-chains. Parameters ---------- keychain_mapping A dict with keys as old key-chains and values as new key-chains. keep_orig Whether to keep the original keys, or start from a new empty container. Default is ``True``. replace Whether to replace the old key-chains by the new ones. Default is ``True``. """ new_cont = self.cont_copy() if keep_orig else ivy.Container() for old_kc, new_kc in keychain_mapping.items(): if replace and old_kc in new_cont: new_cont = new_cont.cont_prune_key_chain(old_kc) new_cont = ivy.Container.cont_combine( new_cont, ivy.Container({new_kc: self[old_kc]}) ) return new_cont def cont_restructure(self, mapping, keep_orig=True, replace=True): """Create a new container with the same contents, but a new key-chain structure, and transposes and/or reshaped arrays. Given by the mapping with keys as old key-chains and values as new key-chains. Parameters ---------- mapping A dict with keys as old key-chains and values as new key-chains. keep_orig Whether to keep the original keys, are start from a new container. Default is ``True``. replace Whether to replace the old key-chains by the new ones. Default is ``True``. """ new_cont = self.cont_copy() if keep_orig else ivy.Container() for old_kc, new in mapping.items(): if replace and old_kc in new_cont: new_cont = new_cont.cont_prune_key_chain(old_kc) val = self[old_kc] if isinstance(new, dict): new_kc = new["key_chain"] if "pattern" in new: pattern = new["pattern"] axes_lengths = new["axes_lengths"] if "axes_lengths" in new else {} if isinstance(val, ivy.Container): val = val.einops_rearrange(pattern, **axes_lengths) else: val = ivy.einops_rearrange(val, pattern, **axes_lengths) else: new_kc = new new_cont = ivy.Container.cont_combine( new_cont, ivy.Container({new_kc: val}) ) return new_cont def cont_flatten_key_chains( self, include_empty=False, above_height=None, below_depth=None ): """Summary. Parameters ---------- include_empty Default value = False) above_height Default value = None) below_depth Default value = None) """ return ivy.Container( { ivy.Container.cont_flatten_key_chain( kc, above_height=above_height, below_depth=below_depth ): v for kc, v in self.cont_to_iterator(include_empty=include_empty) }, **self._config, ) def cont_copy(self): """Create a copy of this container. Returns ------- A copy of the container """ return ivy.Container(self.cont_to_dict(), **self._config) def cont_deep_copy(self): """Create a deep copy (copying all internal tensors) of this container. return: A deep copy of the container """ return self.cont_map(lambda x, kc: ivy.copy_array(x) if ivy.is_array(x) else x) def __deepcopy__(self, memo): return self.cont_deep_copy() def cont_map( self, func, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, inplace=False, key_chain="", ): """Apply function to all array values of container. Parameters ---------- func Function to apply to each container entry key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. inplace Whether to apply the mapping inplace, or return a new container. Default is ``False``. key_chain Chain of keys for this dict entry (Default value = '') Returns ------- New container following the function mapped to each sub-array. """ return_dict = self if inplace else dict() for key, value in self.items(): this_key_chain = key if key_chain == "" else (key_chain + "/" + key) if isinstance(value, ivy.Container): ret = value.cont_map( func, key_chains, to_apply, prune_unapplied, map_sequences, inplace, this_key_chain, ) if prune_unapplied and not ret: continue if not inplace: return_dict[key] = ret elif isinstance(value, (list, tuple)) and map_sequences: ret = ivy.nested_map( value, lambda x: func(x, None), True, shallow=False ) if prune_unapplied and not ret: continue return_dict[key] = ret else: if key_chains is not None: if (this_key_chain in key_chains and not to_apply) or ( this_key_chain not in key_chains and to_apply ): if prune_unapplied: continue return_dict[key] = value continue return_dict[key] = func(value, this_key_chain) if inplace: return self return ivy.Container(return_dict, **self._config) def cont_map_sub_conts( self, func, key_chains=None, to_apply=True, prune_unapplied=False, inplace=False, key_chain="", include_self=True, ): """Apply function to all sub-contains in the container. Parameters ---------- func Function to apply to each sub-container key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. inplace Whether to apply the mapping inplace, or return a new container. Default is ``False``. key_chain Chain of keys for this dict entry (Default value = '') include_self Whether to also apply the (possiby in-place) function to this container. Default is ``True``. Returns ------- New container following the function mapped to each sub-container. """ return_dict = self if inplace else dict() for key, value in self.items(): this_key_chain = key if key_chain == "" else (key_chain + "/" + key) if isinstance(value, ivy.Container): ret = value.cont_map_sub_conts( func, key_chains, to_apply, prune_unapplied, inplace, this_key_chain ) if prune_unapplied and not ret: continue if not inplace: return_dict[key] = ret else: if ( key_chains is not None and ( (this_key_chain in key_chains and not to_apply) or (this_key_chain not in key_chains and to_apply) ) and prune_unapplied ): continue return_dict[key] = value ret = return_dict if inplace else ivy.Container(return_dict, **self._config) if key_chain != "" or include_self: ret = func(ret, key_chain) if inplace: return return ret def cont_with_entries_as_lists(self): def to_list(x, _=""): try: return self._cont_ivy.to_list(x) except (IvyBackendException): return x return self.cont_map(to_list) def cont_reshape_like(self, target_dict, leading_shape=None, return_cont=None): """Set shapes of container entries to shapes specified by new container with the same key structure. Parameters ---------- target_dict param leading_shape: (Default value = None) return_cont Default value = None) leading_shape (Default value = None) Returns ------- ret new container with values of updated shapes """ leading_shape = self._cont_ivy.default(leading_shape, list()) if return_cont is None: return_cont = self.cont_copy() for (_, v_shape), (k, v) in zip(target_dict.items(), return_cont.items()): if isinstance(v_shape, dict): return_cont[k] = self.cont_reshape_like( v_shape, leading_shape, return_cont[k] ) else: return_cont[k] = self._cont_ivy.reshape( v, leading_shape + list(v_shape) ) return ivy.Container(return_cont, **self._config) def cont_create_if_absent(self, key, value, inplace=True): """Add a key to the container with corresponding value, if it is not already present. otherwise, do nothing. Parameters ---------- key param value: inplace Default value = True) value """ if key in self: return self.cont_set_at_key_chain(key, value, inplace) def cont_if_exists(self, key): """Returns the sub-container at the following key if it exists, otherwise None. Parameters ---------- key """ try: return self[key] except KeyError: return def cont_try_kc(self, key): """Tries the following key or key chain, returning self if not present. Parameters ---------- key """ try: return self[key] except IvyException: return self def cont_cutoff_at_depth(self, depth_cutoff, inplace=False): """Summary. Parameters ---------- depth_cutoff param inplace: (Default value = False) inplace (Default value = False) """ total_depth = self.cont_max_depth copy = self.cont_copy() def _maybe_cutoff(cont, kc): if total_depth - copy[kc].cont_max_depth < depth_cutoff: return cont if inplace: cont.clear() return ivy.Container() ret = self.cont_map_sub_conts(_maybe_cutoff, inplace=inplace) if inplace: return return ret def cont_cutoff_at_height(self, height_cutoff, inplace=False): """Summary. Parameters ---------- height_cutoff param inplace: (Default value = False) inplace (Default value = False) """ copy = self.cont_copy() def _maybe_cutoff(cont, kc): if copy[kc].cont_max_depth > height_cutoff: return cont if inplace: cont.clear() return ivy.Container() ret = self.cont_map_sub_conts(_maybe_cutoff, inplace=inplace) if inplace: return return ret def _cont_slice_keys(self, key_slice): keys = list(self.keys()) if isinstance(key_slice, str): ivy.assertions.check_true(len(key_slice) == 3 and key_slice[1] == ":") ivy.assertions.check_true(self._alphabetical_keys) start_char = key_slice[0] end_char = key_slice[2] start_idx = min([i for i, k in enumerate(keys) if k[0] == start_char]) end_idx = max([i for i, k in enumerate(keys) if k[0] == end_char]) + 1 key_slice = slice(start_idx, end_idx, 1) ret = self.cont_copy() desired_keys = keys[key_slice] # noinspection PyUnresolvedReferences return ret.cont_at_key_chains(desired_keys) def cont_slice_keys(self, key_slice, all_depths=False): """Summary. Parameters ---------- key_slice param all_depths: (Default value = False) all_depths (Default value = False) """ top_depth = self.cont_max_depth if all_depths: if isinstance(key_slice, dict): first_slice = list(key_slice.values())[0] for d in range(0, top_depth + 1): if d not in key_slice: key_slice[d] = first_slice else: key_slice = {d: key_slice for d in range(0, top_depth + 1)} if isinstance(key_slice, dict): def _fn(cont, kc): depth = 0 if kc == "" else len(kc.split("/")) if depth in key_slice: # noinspection PyProtectedMember return cont._cont_slice_keys(key_slice[depth]) return cont return self.cont_map_sub_conts(_fn) return self._cont_slice_keys(key_slice) def cont_with_print_limit(self, print_limit, inplace=False): """Summary. Parameters ---------- print_limit param inplace: (Default value = False) inplace (Default value = False) """ def _update_print_limit(cont, _): cont._print_limit = print_limit return cont ret = self.cont_map_sub_conts(_update_print_limit, inplace=inplace) if inplace: return return ret def cont_remove_print_limit(self, inplace=False): """Summary. Parameters ---------- inplace Default value = False) """ return self.cont_with_print_limit(None, inplace) def cont_with_key_length_limit(self, key_length_limit, inplace=False): """Summary. Parameters ---------- key_length_limit param inplace: (Default value = False) inplace (Default value = False) """ def _update_key_length_limit(cont, _): cont._key_length_limit = key_length_limit return cont ret = self.cont_map_sub_conts(_update_key_length_limit, inplace=inplace) if inplace: return return ret def cont_remove_key_length_limit(self, inplace=False): """Summary. Parameters ---------- inplace Default value = False) """ return self.cont_with_key_length_limit(None, inplace) def cont_with_print_indent(self, print_indent, inplace=False): """Summary. Parameters ---------- print_indent param inplace: (Default value = False) inplace (Default value = False) """ def _update_print_indent(cont, _): cont._print_indent = print_indent return cont ret = self.cont_map_sub_conts(_update_print_indent, inplace=inplace) if inplace: return return ret def cont_with_print_line_spacing(self, print_line_spacing, inplace=False): """Summary. Parameters ---------- print_line_spacing param inplace: (Default value = False) inplace (Default value = False) """ def _update_print_line_spacing(cont, _): cont._print_line_spacing = print_line_spacing return cont ret = self.cont_map_sub_conts(_update_print_line_spacing, inplace=inplace) if inplace: return return ret def cont_with_default_key_color(self, default_key_color, inplace=False): """Summary. Parameters ---------- default_key_color param inplace: (Default value = False) inplace (Default value = False) """ def _update_default_key_color(cont, _): cont._default_key_color = default_key_color return cont ret = self.cont_map_sub_conts(_update_default_key_color, inplace=inplace) if inplace: return return ret def cont_with_ivy_backend(self, ivy_backend: str, inplace=False): """Summary. Parameters ---------- self input Container ivy_backend backend to use inplace whether to modify the container or return a copy """ if inplace: self._cont_ivy = ivy_backend self._config["ivyh"] = ivy_backend return self else: return ivy.Container(self, ivyh=ivy_backend) def cont_show(self): print(self) def cont_show_sub_container(self, sub_cont_or_keychain): """Summary. Parameters ---------- sub_cont_or_keychain """ # copy this container this_cont = self.cont_copy() # get the sub-container if isinstance(sub_cont_or_keychain, str): sub_cont = self.cont_at_key_chain(sub_cont_or_keychain) else: sub_cont = sub_cont_or_keychain # find the key chain of the sub-container sub_cont_kc = self.cont_find_sub_container(sub_cont) # show this container if key-chain not found, and return if not sub_cont_kc: print(self) return # otherwise, replace sub-container in this container with known key this_cont[sub_cont_kc] = ivy.Container({"SUB_CONT": None}) # get the formatted reprs this_repr = this_cont.cont_with_default_key_color("green").__repr__() this_repr_red = this_cont.cont_with_default_key_color("red").__repr__() this_repr_stripped = ansi_escape.sub("", this_repr) sub_repr = sub_cont.cont_with_default_key_color("red").__repr__() # remove the outer brackets from the sub repr sub_repr = "\n" + "\n".join(sub_repr.split("\n")[1:-1]) + "\n" # find the sub-container placeholder idx = this_repr_stripped.find("SUB_CONT: null") # count the lines above and below the sub-container num_lines_above = this_repr_stripped[0:idx].count("\n") num_lines_below = this_repr_stripped[idx:].count("\n") # get the str reprs above and below this_repr_split = this_repr.split("\n") this_repr_red_split = this_repr_red.split("\n") this_repr_above = "\n".join( this_repr_split[0 : num_lines_above - 1] + [this_repr_red_split[num_lines_above - 1]] ) this_repr_below = "\n".join(this_repr_split[-num_lines_below:]) # count the number of lines needed to be prepended to the sub-container repr cur_num_spaces = 0 for i, s in enumerate(sub_repr[1:]): if s != " ": break cur_num_spaces += 1 exp_num_spaces = 0 for i, s in enumerate(this_repr.split("\n")[num_lines_above]): if s != " ": break exp_num_spaces += 1 num_spaces_to_add = exp_num_spaces - cur_num_spaces # prepend these lines to the sub-container sub_repr = ( "\n" + "\n".join( [" " * num_spaces_to_add + s for s in sub_repr[1:-1].split("\n")] ) + "\n" ) # show print(this_repr_above + sub_repr + this_repr_below) def __repr__(self, as_repr=True): indent_str = " " * self._print_indent def _align_array(array_str_in): array_str_in_split = array_str_in.split("([") leading_str_to_keep = array_str_in_split[0].replace("\\n", "") indented_key_size = len(leading_str_to_keep.replace('"', "").split(": ")[0]) indented_key_str = " " * (indented_key_size + 2) padded = False def _pre_pad_alpha_line(str_in): nonlocal padded padded = True return "\\n" + indent_str + indented_key_str + str_in leading_str_to_keep = ", ".join( [ _pre_pad_alpha_line(s) if s[0].isalpha() and i != 0 else s for i, s in enumerate(leading_str_to_keep.split(", ")) ] ) local_indent_str = "" if padded else indent_str leading_str = leading_str_to_keep.split("\\n")[-1].replace('"', "") remaining_str = array_str_in_split[1] num_extra_dims = 0 for i, char in enumerate(remaining_str): if char != "[": num_extra_dims = i break extra_indent = (len(leading_str) + 1 + num_extra_dims) * " " array_str_in = "([".join([leading_str_to_keep, remaining_str]) uniform_indent_wo_overflow = array_str_in.replace( "\\n[", "\n" + local_indent_str + extra_indent + "[" ) uniform_indent_wo_overflow_list = list( filter(None, uniform_indent_wo_overflow.split("\\n")) ) uniform_indent = "\n".join( [ local_indent_str + extra_indent + " " + s if ( s[0].isnumeric() or s[0] == "-" or s[0:3] == "..." or max([ss in s[0:6] for ss in ["nan, ", "inf, "]]) ) else ( indent_str + indented_key_str + s if (not s[0].isspace() and s[0] != '"') else s ) for s in uniform_indent_wo_overflow_list ] ) indented = uniform_indent # 10 dimensions is a sensible upper bound for the number in a single array for i in range(2, 10): indented = indented.replace(" " * (i - 1) + "[" * i, "[" * i) indented = "\n".join( [s for s in indented.split("\n") if bool(s) and not s.isspace()] ) return indented def _align_arrays(str_in): chunks = str_in.split("\n" + indent_str) aligned_array_chunks = { i: _align_array(c) for i, c in enumerate(chunks) if "\\n" in c } chunks = [ aligned_array_chunks[i] if i in aligned_array_chunks else c_orig for i, c_orig in enumerate(chunks) ] return ("\n" + indent_str).join(chunks) new_dict = dict() for k, v in self.items(): if isinstance(v, ivy.Container): # noinspection PyArgumentList rep = v.__repr__(as_repr=False) else: if ( (self._cont_ivy.is_native_array(v) or isinstance(v, ivy.Array)) and len(list(v.shape)) > 0 and ivy.exists(self._print_limit) and reduce(mul, v.shape) > self._print_limit ): rep = (type(v), "shape=", list(v.shape)) elif ( isinstance(v, (list, tuple)) and v and ( self._cont_ivy.is_native_array(v[0]) or isinstance(v[0], ivy.Array) ) ): if ( isinstance(v, tuple) and hasattr(v, "_asdict") and hasattr(v, "_fields") ): if len(v) <= self._print_limit: rep = tuple( [ "{} = {}".format(name, v[i]) if v[i].size < self._print_limit else "{} = {}, shape={}".format( name, type(v[i]), list(v[i].shape) ) for i, name in enumerate(v._fields) ], ) else: rep = ( "NamedTuple({})".format(len(v)), type(v[0]), "shape={}".format(list(v[0].shape)), ) elif isinstance(v, tuple): rep = ( "tuple({})".format(len(v)), type(v[0]), "shape={}".format(list(v[0].shape)), ) else: rep = ( "list[{}]".format(len(v)), type(v[0]), "shape={}".format(list(v[0].shape)), ) else: rep = v new_dict[k] = rep if as_repr: json_dumped_str = _align_arrays( json.dumps( ivy.Container(new_dict, **self._config) .cont_map( lambda x, kc: x if _is_jsonable(x) else _repr(x).replace(" ", "").replace(",", ", ") ) .cont_to_dict(), indent=self._print_indent, ) ) def _add_newline(str_in): str_in_split = str_in.split("\n") str_split_size = len(str_in_split) return "\n".join( [ ("\n" * self._print_line_spacing + ss) if i == (str_split_size - 1) else ss for i, ss in enumerate(str_in_split) ] ) json_dumped_str = '":'.join( [_add_newline(s) for s in json_dumped_str.split('":')] ) # improve tf formatting if ivy.backend_stack and ivy.current_backend_str() == "tensorflow": json_dumped_str_split = json_dumped_str.split("'Variable:") json_dumped_str = ( json_dumped_str_split[0] + ", " + ", ".join( [ "'".join(ss.split("'")[1:]) for ss in json_dumped_str_split[1:] ] ) ) json_dumped_str = ( json_dumped_str.replace(":shape", ", shape") .replace(")dtype=", "), dtype=") .replace(", ),", ",),") ) json_dumped_str = re.sub("}, $", "}", json_dumped_str) # color keys json_dumped_str_split = json_dumped_str.split('":') split_size = len(json_dumped_str_split) json_dumped_str = '":'.join( [ ' "'.join( sub_str.split(' "')[:-1] + [ termcolor.colored( ivy.Container.cont_trim_key( sub_str.split(' "')[-1], self._key_length_limit ), self._default_key_color, ) ] ) if i < split_size - 1 else sub_str for i, sub_str in enumerate(json_dumped_str_split) ] ) # remove quotation marks, shape tuple, and color other elements of the dict ret = ( json_dumped_str.replace('"', "") .replace(", 'shape=', [", " shape=[") .replace(":", termcolor.colored(":", "magenta")) .replace("{", termcolor.colored("{", "blue")) .replace("}", termcolor.colored("}", "blue")) .replace("shape=", termcolor.colored("shape=", "magenta")) .replace("device=", termcolor.colored("device=", "magenta")) .replace("<class'", "<class '") .replace("'", "") .replace("<class", "<" + termcolor.colored("class", "blue")) ) # ToDo: make the solution below more elegant for i in range(10): ret = ret.replace( "diff_{}".format(i), termcolor.colored("diff_{}".format(i), "red") ) for keyword, color in self._keyword_color_dict.items(): ret = ret.replace(keyword, termcolor.colored(keyword, color)) return ret return new_dict def __dir__(self): return list(super.__dir__(self)) + list(self.keys()) def __getattr__(self, item, *args, **kwargs): try: ret = dict.__getitem__(self, item) except KeyError: # noinspection PyUnresolvedReferences ret = ivy.Container() for k, v in self.items(): if isinstance(v, ivy.Container): result = v.__getattr__(item, *args, **kwargs) else: # raise error if not hasattr(v, item): raise AttributeError( "'{}' object has no attribute '{}'".format( type(v).__module__, item ) ) attr = getattr(v, item) result = attr(*args, **kwargs) if callable(attr) else attr ret.__setitem__(k, result) return ret def __setattr__(self, name, value): if name[0] != "_": self[name] = value else: super.__setattr__(self, name, value) def _get_queue_item(self, query): if isinstance(query, int): queue_queries = [query] elif isinstance(query, slice): queue_queries = list( range(query.start, query.stop, ivy.default(query.step, 1)) ) elif isinstance(query, (list, tuple)): queue_queries = list( range(query[0].start, query[0].stop, ivy.default(query[0].step, 1)) ) else: raise ivy.exceptions.IvyException( "Invalid slice type, must be one of integer, slice " "or sequences of slices." ) queue_idxs = set( [np.sum(q >= self._queue_load_sizes_cum).item() for q in queue_queries] ) conts = list() for i in queue_idxs: if i not in self._loaded_containers_from_queues: cont = ivy.Container( self._queues[i].get(timeout=self._queue_timeout), **self._config ).to_ivy() self._loaded_containers_from_queues[i] = cont else: cont = self._loaded_containers_from_queues[i] conts.append(cont) combined_cont = self._container_combine_method(conts) idx = list(queue_idxs)[0] offset = 0 if idx == 0 else self._queue_load_sizes_cum[idx - 1] if isinstance(query, int): shifted_query = query - offset elif isinstance(query, slice): shifted_query = slice(query.start - offset, query.stop - offset, query.step) elif isinstance(query, (list, tuple)): shifted_query = tuple( [ slice(slc.start - offset, slc.stop - offset, slc.step) for slc in query ] ) # noinspection PyUnboundLocalVariable return combined_cont[shifted_query] def __getitem__(self, query): """Get slice, key or key chain of container object. Parameters ---------- query slice or str slice object, key or key chain to query all container elements. Returns ------- Container object at desired query. """ if isinstance(query, str): if query == "": return self if "/" in query or "." in query: ret = self.cont_at_key_chain(query) return ret ret = dict.__getitem__(self, query) return ret elif ivy.exists(self._queues): ret = self._get_queue_item(query) return ret return_dict = dict() for key, value in self.items(): if isinstance(value, ivy.Container): return_dict[key] = value[query] else: # noinspection PyBroadException if isinstance(value, list) or isinstance(value, tuple): if len(value) == 0: return_dict[key] = value else: return_dict[key] = value[query] elif value is None or hasattr(value, "shape") and value.shape == (): return_dict[key] = value else: return_dict[key] = value[query] ret = ivy.Container(return_dict, **self._config) return ret def __setitem__(self, query, val): """Set key or key chain of container object. Parameters ---------- query slice or str slice object, key or key chain at which to set all container elements. val ivy.Container, array, or other The value to set at the desired query. Returns ------- New container after updating. """ if isinstance(query, str) and ("/" in query or "." in query): return self.cont_set_at_key_chain(query, val, inplace=True) else: return dict.__setitem__(self, query, val) def __contains__(self, key): if isinstance(key, str) and ("/" in key or "." in key): return self.cont_has_key_chain(key) elif isinstance(key, ivy.Container): return self.cont_contains_sub_container(key) else: return dict.__contains__(self, key) def __getstate__(self): state_dict = copy.copy(self.__dict__) state_dict["_local_ivy"] = ivy.try_else_none( lambda: state_dict["_local_ivy"].current_backend_str() ) config_in = copy.copy(state_dict["_config_in"]) config_in["ivyh"] = ivy.try_else_none( lambda: config_in["ivyh"].current_backend_str() ) state_dict["_config_in"] = config_in config = copy.copy(state_dict["_config"]) config["ivyh"] = ivy.try_else_none(lambda: config["ivyh"].current_backend_str()) state_dict["_config"] = config return state_dict def __setstate__(self, state_dict): if "_local_ivy" in state_dict: if ivy.exists(state_dict["_local_ivy"]): state_dict["_local_ivy"] = ivy.get_backend(state_dict["_local_ivy"]) if "_config_in" in state_dict: config_in = copy.copy(state_dict["_config_in"]) if "ivyh" in config_in: if ivy.exists(config_in["ivyh"]): config_in["ivyh"] = ivy.get_backend(config_in["ivyh"]) state_dict["_config_in"] = config_in if "_config" in state_dict: config = copy.copy(state_dict["_config"]) if "ivyh" in config: if ivy.exists(config["ivyh"]): config["ivyh"] = ivy.get_backend(config["ivyh"]) state_dict["_config"] = config self.__dict__.update(state_dict) def _cont_ivy(self): return ivy.default(self._local_ivy, ivy) def _cont_ivy(self, local_ivy): self._local_ivy = local_ivy def cont_shape(self): """The shape of the arrays in the container, with None placed in indices which are not consistent across arrays. """ return self._cont_get_shape() def cont_shapes(self): """The shapes of each array in the container, with None placed in leaf entries without a shape attribute. """ return self._cont_get_shapes() def cont_dev(self): """The device to which the arrays in the container belong, with None returned if the devices are not consistent. """ return self._cont_get_dev() def cont_dev_str(self): """The device to which the arrays in the container belong, with None returned if the devices are not consistent. """ return self._cont_get_dev() def cont_ivy(self): return self._cont_ivy def cont_config(self): return self._config def cont_max_depth(self): kcs = [kc for kc in self.cont_to_iterator_keys(include_empty=True)] if not kcs: return 0 return max([len(kc.split("/")) for kc in kcs]) #ivy.container.container # global import copy import operator # local import ivy from .activations import ContainerWithActivations from .base import ContainerBase from .conversions import ContainerWithConversions from .creation import ContainerWithCreation from .data_type import ContainerWithDataTypes from .device import ContainerWithDevice from .elementwise import ContainerWithElementwise from .general import ContainerWithGeneral from .gradients import ContainerWithGradients from .image import ContainerWithImage from .layers import ContainerWithLayers from .linear_algebra import ContainerWithLinearAlgebra from .losses import ContainerWithLosses from .manipulation import ContainerWithManipulation from .norms import ContainerWithNorms from .random import ContainerWithRandom from .searching import ContainerWithSearching from .set import ContainerWithSet from .sorting import ContainerWithSorting from .statistical import ContainerWithStatistical from .utility import ContainerWithUtility from ivy.container.experimental import ( ContainerWithActivationExperimental, ContainerWithConversionExperimental, ContainerWithCreationExperimental, ContainerWithData_typeExperimental, ContainerWithDeviceExperimental, ContainerWithElementWiseExperimental, ContainerWithGeneralExperimental, ContainerWithGradientsExperimental, ContainerWithImageExperimental, ContainerWithLayersExperimental, ContainerWithLinearAlgebraExperimental, ContainerWithLossesExperimental, ContainerWithManipulationExperimental, ContainerWithNormsExperimental, ContainerWithRandomExperimental, ContainerWithSearchingExperimental, ContainerWithSetExperimental, ContainerWithSortingExperimental, ContainerWithStatisticalExperimental, ContainerWithUtilityExperimental, ) def __init__( self, dict_in=None, queues=None, queue_load_sizes=None, container_combine_method="list_join", queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color="green", keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, **kwargs ): ContainerBase.__init__( self, dict_in, queues, queue_load_sizes, container_combine_method, queue_timeout, print_limit, key_length_limit, print_indent, print_line_spacing, ivyh, default_key_color, keyword_color_dict, rebuild_child_containers, types_to_iteratively_nest, alphabetical_keys, **kwargs ) def __pos__(self): return self def __neg__(self): return self.cont_map(lambda x, kc: -x, map_sequences=True) def __pow__(self, power): """ ivy.Container special method for the power operator, calling :code:`operator.pow` for each of the corresponding leaves of the two containers. Parameters ---------- self input container. Should have a numeric data type. power input array or container of powers. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. Returns ------- ret a container containing the element-wise sums. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = x ** 2 >>> print(y) { a: ivy.array([0, 1]), b: ivy.array([4, 9]) } >>> x = ivy.Container(a=ivy.array([0, 1.2]), b=ivy.array([2.2, 3.])) >>> y = x ** 3.1 >>> print(y) { a: ivy.array([0., 1.75979435]), b: ivy.array([11.52153397, 30.13532257]) } """ if isinstance(power, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.pow(xs[0], xs[1]), [self, power], map_nests=True ) return self.cont_map(lambda x, kc: x**power, map_sequences=True) def __rpow__(self, power): return self.cont_map(lambda x, kc: power**x, map_sequences=True) def __add__(self, other): """ ivy.Container special method for the add operator, calling :code:`operator.add` for each of the corresponding leaves of the two containers. Parameters ---------- self first input container. Should have a numeric data type. other second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. Returns ------- ret a container containing the element-wise sums. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- With :code:`Number` instances at the leaves: >>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=3, b=4) >>> z = x + y >>> print(z) { a: 4, b: 6 } With :class:`ivy.Array` instances at the leaves: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = x + y >>> print(z) { a: ivy.array([5, 7, 9]), b: ivy.array([7, 9, 11]) } With a mix of :class:`ivy.Container` and :class:`ivy.Array` instances: >>> x = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), ... b=ivy.array([[5.], [6.], [7.]])) >>> y = ivy.array([[1.1, 2.3, -3.6]]) >>> z = x + y >>> print(z) { a: ivy.array([[5.1, 6.3, 0.4], [6.1, 7.3, 1.4], [7.1, 8.3, 2.4]]), b: ivy.array([[6.1, 7.3, 1.4], [7.1, 8.3, 2.4], [8.1, 9.3, 3.4]]) } """ return ivy.Container.cont_multi_map( lambda xs, _: operator.add(xs[0], xs[1]), [self, other], map_nests=True ) def __radd__(self, other): """ ivy.Container reverse special method for the add operator, calling :code:`operator.add` for each of the corresponding leaves of the two containers. Parameters ---------- self first input container. Should have a numeric data type. other second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. Returns ------- ret a container containing the element-wise sums. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = 1 >>> y = ivy.Container(a=3, b=4) >>> z = x + y >>> print(z) { a: 4, b: 5 } """ return ivy.Container.cont_multi_map( lambda xs, _: operator.add(xs[0], xs[1]), [other, self], map_nests=True ) def __sub__(self, other): """ ivy.Container special method for the subtract operator, calling :code:`operator.sub` for each of the corresponding leaves of the two containers. Parameters ---------- self first input container. Should have a numeric data type. other second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. Returns ------- ret a container containing the element-wise differences. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- With :code:`Number` instances at the leaves: >>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=3, b=4) >>> z = x - y >>> print(z) { a: -2, b: -2 } With :class:`ivy.Array` instances at the leaves: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([4, 3, 2])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([6, 5, 4])) >>> z = x - y >>> print(z) { a: ivy.array([-3, -3, -3]), b: ivy.array([-2, -2, -2]) } With a mix of :class:`ivy.Container` and :class:`ivy.Array` instances: >>> x = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), ... b=ivy.array([[5.], [6.], [7.]])) >>> y = ivy.array([[1.1, 2.3, -3.6]]) >>> z = x - y >>> print(z) { a: ivy.array([[2.9, 1.7, 7.6], [3.9, 2.7, 8.6], [4.9, 3.7, 9.6]]), b: ivy.array([[3.9, 2.7, 8.6], [4.9, 3.7, 9.6], [5.9, 4.7, 10.6]]) } """ return ivy.Container.cont_multi_map( lambda xs, _: operator.sub(xs[0], xs[1]), [self, other], map_nests=True ) def __rsub__(self, other): """ ivy.Container reverse special method for the subtract operator, calling :code:`operator.sub` for each of the corresponding leaves of the two containers. Parameters ---------- self first input container. Should have a numeric data type. other second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. Returns ------- ret a container containing the element-wise differences. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = 1 >>> y = ivy.Container(a=3, b=4) >>> z = x - y >>> print(z) { a: -2, b: -3 } """ return ivy.Container.cont_multi_map( lambda xs, _: operator.sub(xs[0], xs[1]), [other, self], map_nests=True ) def __mul__(self, other): return ivy.Container.cont_multi_map( lambda xs, _: operator.mul(xs[0], xs[1]), [self, other], map_nests=True ) def __rmul__(self, other): return ivy.Container.cont_multi_map( lambda xs, _: operator.mul(xs[0], xs[1]), [other, self], map_nests=True ) def __truediv__(self, other): """ ivy.Container special method for the divide operator, calling :code:`operator.truediv` for each of the corresponding leaves of the two containers. Parameters ---------- self first input container. Should have a numeric data type. other second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. Returns ------- ret a container containing the element-wise differences. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- With :code:`Number` instances at the leaves: >>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=5, b=4) >>> z = x / y >>> print(z) { a: 0.2, b: 0.5 } With :class:`ivy.Array` instances at the leaves: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([4, 3, 2])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([6, 5, 4])) >>> z = x / y >>> print(z) { a: ivy.array([0.25, 0.40000001, 0.5]), b: ivy.array([0.66666669, 0.60000002, 0.5]) } """ return ivy.Container.cont_multi_map( lambda xs, _: operator.truediv(xs[0], xs[1]), [self, other], map_nests=True ) def __rtruediv__(self, other): return ivy.Container.cont_multi_map( lambda xs, _: operator.truediv(xs[0], xs[1]), [other, self], map_nests=True ) def __floordiv__(self, other): if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.floordiv(xs[0], xs[1]), [self, other], map_nests=True, ) return self.cont_map(lambda x, kc: x // other, map_sequences=True) def __rfloordiv__(self, other): return self.cont_map(lambda x, kc: other // x, map_sequences=True) def __abs__(self): """ ivy.Container special method for the abs operator, calling :code:`operator.abs` for each of the corresponding leaves of the two containers. Parameters ---------- self input Container. Should have leaves with numeric data type. Returns ------- ret A container containing the element-wise results. Examples -------- With :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([1, -2, 3]), ... b=ivy.array([-1, 0, 5])) >>> y = abs(x) >>> print(y) { a: ivy.array([1, 2, 3]), b: ivy.array([1, 0, 5]) } """ return self.cont_map(lambda x, kc: operator.abs(x), map_sequences=True) def __lt__(self, other): """ ivy.Container special method for the less operator, calling :code:`operator.lt` for each of the corresponding leaves of the two containers. Parameters ---------- self first input Container. May have any data type. other second input Container. Must be compatible with x1 (with Broadcasting). May have any data type. Returns ------- ret A container containing the element-wise results. Any returned array inside must have a data type of bool. Examples -------- With :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x < y >>> print(z) { a: ivy.array([False, False, False]), b: ivy.array([True, False, True]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.lt(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x < other, map_sequences=True) def __le__(self, other): """ ivy.Container special method for the less_equal operator, calling :code:`operator.le` for each of the corresponding leaves of the two containers. Parameters ---------- self first input Container. May have any data type. other second input Container. Must be compatible with x1 (with Broadcasting). May have any data type. Returns ------- ret A container containing the element-wise results. Any returned array inside must have a data type of bool. Examples -------- With :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x <= y >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, True, True]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.le(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x <= other, map_sequences=True) def __eq__(self, other): """ ivy.Container special method for the equal operator, calling :code:`operator.eq` for each of the corresponding leaves of the two containers. Parameters ---------- self first input Container. May have any data type. other second input Container. Must be compatible with x1 (with Broadcasting). May have any data type. Returns ------- ret A container containing the element-wise results. Any returned array inside must have a data type of bool. Examples -------- With :class:`ivy.Container` instances: >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 3, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 4, 5])) >>> y = x1 == x2 >>> print(y) { a: ivy.array([True, True, True]), b: ivy.array([True, False, True]) } >>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 3, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 == x2 >>> print(y) { a: ivy.array([True, False, True]), b: ivy.array([True, True, True]) } >>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 == x2 >>> print(y) { a: ivy.array([True, True, True]), b: ivy.array([True, True, True]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.eq(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x == other, map_sequences=True) def __ne__(self, other): """ ivy.Container special method for the not_equal operator, calling :code:`operator.ne` for each of the corresponding leaves of the two containers. Parameters ---------- self first input Container. May have any data type. other second input Container. Must be compatible with x1 (with Broadcasting). May have any data type. Returns ------- ret A container containing the element-wise results. Any returned array inside must have a data type of bool. Examples -------- With :class:`ivy.Container` instances: >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 3, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([1, 4, 5])) >>> y = x1 != x2 >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([False, True, False]) } >>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 3, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 != x2 >>> print(y) { a: ivy.array([False, True, False]), b: ivy.array([False, False, False]) } >>> x1 = ivy.Container(a=ivy.array([1.0, 2.0, 3.0]), ... b=ivy.array([1, 4, 5])) >>> x2 = ivy.Container(a=ivy.array([1, 2, 3.0]), ... b=ivy.array([1.0, 4.0, 5.0])) >>> y = x1 != x2 >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([False, False, False]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.ne(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x != other, map_sequences=True) def __gt__(self, other): """ ivy.Container special method for the greater operator, calling :code:`operator.gt` for each of the corresponding leaves of the two containers. Parameters ---------- self first input Container. May have any data type. other second input Container. Must be compatible with x1 (with Broadcasting). May have any data type. Returns ------- ret A container containing the element-wise results. Any returned array inside must have a data type of bool. Examples -------- With :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x > y >>> print(z) { a:ivy.array([True,False,True]), b:ivy.array([False,False,False]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.gt(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x > other, map_sequences=True) def __ge__(self, other): """ ivy.Container special method for the greater_equal operator, calling :code:`operator.ge` for each of the corresponding leaves of the two containers. Parameters ---------- self first input Container. May have any data type. other second input Container. Must be compatible with x1 (with Broadcasting). May have any data type. Returns ------- ret A container containing the element-wise results. Any returned array inside must have a data type of bool. Examples -------- With :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([4, 5, 6]),b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 5, 3]),b=ivy.array([5, 3, 7])) >>> z = x >= y >>> print(z) { a:ivy.array([True,True,True]), b:ivy.array([False,True,False]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.ge(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x >= other, map_sequences=True) def __and__(self, other): if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.and_(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x and other, map_sequences=True) def __rand__(self, other): return self.cont_map(lambda x, kc: other and x, map_sequences=True) def __or__(self, other): if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.or_(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: x or other, map_sequences=True) def __ror__(self, other): return self.cont_map(lambda x, kc: other or x, map_sequences=True) def __invert__(self): return self.cont_map(lambda x, kc: operator.not_(x), map_sequences=True) def __xor__(self, other): """ ivy.Container special method for the ge operator, calling :code:`operator.ge` for each of the corresponding leaves of the two containers. Parameters ---------- self first input Container. other second input Container. Arrays inside must be compatible with ``x1`` (see :ref:`broadcasting`). Should have an integer or boolean data type. Returns ------- ret a container containing the element-wise results. Any returned arrays inside must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([89]), b=ivy.array([2])) >>> y = ivy.Container(a=ivy.array([12]), b=ivy.array([3])) >>> z = x ^ y >>> print(z) { a: ivy.array([85]), b: ivy.array([1]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.xor(xs[0], xs[1]), [self, other], map_nests=True ) return self.cont_map(lambda x, kc: operator.xor(x, other), map_sequences=True) def __rxor__(self, other): return self.cont_map(lambda x, kc: other != x, map_sequences=True) def __rshift__(self, other): """ ivy.Container special method for the right shift operator, calling :code:`operator.rshift` for each of the corresponding leaves of the two containers. Parameters ---------- self first input container. Should have an integer data type. other second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have an integer data type. Each element must be greater than or equal to ``0``. Returns ------- ret a container containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- With :code:`Number` instances at the leaves: >>> x = ivy.Container(a=128, b=43) >>> y = ivy.Container(a=5, b=3) >>> z = x >> y >>> print(z) { a: 4, b: 5 } With :class:`ivy.Array` instances at the leaves: >>> x = ivy.Container(a=ivy.array([16, 40, 120]), ... b=ivy.array([15, 45, 143])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([0, 3, 4])) >>> z = x >> y >>> print(z) { a: ivy.array([8, 10, 15]), b: ivy.array([15, 5, 8]) } With a mix of :class:`ivy.Container` and :class:`ivy.Array` instances: >>> x = ivy.Container(a=ivy.array([16, 40, 120]), ... b=ivy.array([15, 45, 143])) >>> y = ivy.array([1, 2, 3]) >>> z = x >> y >>> print(z) { a: ivy.array([8, 10, 15]), b: ivy.array([7, 11, 17]) } """ if isinstance(other, ivy.Container): return ivy.Container.cont_multi_map( lambda xs, _: operator.rshift(xs[0], xs[1]), [self, other], map_nests=True, ) return self.cont_map( lambda x, kc: operator.rshift(x, other), map_sequences=True ) def __rrshift__(self, other): """ ivy.Container reverse special method for the right shift operator, calling :code:`operator.rshift` for each of the corresponding leaves of the two containers. Parameters ---------- self first input container. Should have an integer data type. other second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have an integer data type. Each element must be greater than or equal to ``0``. Returns ------- ret a container containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- >>> a = 64 >>> b = ivy.Container(a = ivy.array([0, 1, 2]), ... b = ivy.array([3, 4, 5])) >>> y = a >> b >>> print(y) { a: ivy.array([64, 32, 16]), b: ivy.array([8, 4, 2]) } """ return self.cont_map(lambda x, kc: other >> x, map_sequences=True) def __getstate__(self): state_dict = copy.copy(self.__dict__) state_dict["_local_ivy"] = ( state_dict["_local_ivy"].current_backend_str() if state_dict["_local_ivy"] is not None else None ) config_in = copy.copy(state_dict["_config_in"]) config_in["ivyh"] = ( config_in["ivyh"].current_backend_str() if config_in["ivyh"] is not None else None ) state_dict["_config_in"] = config_in config = copy.copy(state_dict["_config"]) config["ivyh"] = ( config["ivyh"].current_backend_str() if config["ivyh"] is not None else None ) state_dict["_config"] = config return state_dict def __setstate__(self, state_dict): if "_local_ivy" in state_dict: if ivy.exists(state_dict["_local_ivy"]): if len(state_dict["_local_ivy"]) > 0: state_dict["_local_ivy"] = ivy.get_backend(state_dict["_local_ivy"]) else: state_dict["_local_ivy"] = ivy if "_config_in" in state_dict: config_in = copy.copy(state_dict["_config_in"]) if "ivyh" in config_in: if ivy.exists(config_in["ivyh"]): if len(config_in["ivyh"]) > 0: config_in["ivyh"] = ivy.get_backend(config_in["ivyh"]) else: config_in["ivyh"] = ivy state_dict["_config_in"] = config_in if "_config" in state_dict: config = copy.copy(state_dict["_config"]) if "ivyh" in config: if ivy.exists(config["ivyh"]): if len(config["ivyh"]) > 0: config["ivyh"] = ivy.get_backend(config["ivyh"]) else: config["ivyh"] = ivy state_dict["_config"] = config self.__dict__.update(state_dict) #ivy.container.conversions """Collection of Ivy functions for wrapping functions to accept and return ivy.Container instances. """ # global from typing import Union, Dict, Optional, List # local import ivy from ivy.container.base import ContainerBase def static_to_native( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], nested: bool = False, include_derived: Dict[type, bool] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.to_native. This method simply wraps the function, and so the docstring for ivy.to_native also applies to this method with minimal changes. Parameters ---------- x The input to be converted. nested Whether to apply the conversion on arguments in a nested manner. If so, all dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is ``False``. include_derived Whether to also recursive for classes derived from tuple, list and dict. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container object with all sub-arrays converted to their native format. """ return ContainerBase.cont_multi_map_in_function( "to_native", x, nested=nested, include_derived=include_derived, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, ) def to_native( self: ivy.Container, nested: bool = False, include_derived: Dict[type, bool] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.to_native. This method simply wraps the function, and so the docstring for ivy.to_native also applies to this method with minimal changes. Parameters ---------- self The input to be converted. nested Whether to apply the conversion on arguments in a nested manner. If so, all dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is ``False``. include_derived Whether to also recursive for classes derived from tuple, list and dict. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container object with all sub-arrays converted to their native format. """ return self.static_to_native( self, nested, include_derived, key_chains, to_apply, prune_unapplied, map_sequences, out=out, ) def static_to_ivy( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], nested: bool = False, include_derived: Dict[type, bool] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.to_ivy. This method simply wraps the function, and so the docstring for ivy.to_ivy also applies to this method with minimal changes. Parameters ---------- x The input to be converted. nested Whether to apply the conversion on arguments in a nested manner. If so, all dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is ``False``. include_derived Whether to also recursive for classes derived from tuple, list and dict. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container object with all native sub-arrays converted to their ivy.Array instances. """ return ContainerBase.cont_multi_map_in_function( "to_ivy", x, nested=nested, include_derived=include_derived, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, ) def to_ivy( self: ivy.Container, nested: bool = False, include_derived: Dict[type, bool] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.to_ivy. This method simply wraps the function, and so the docstring for ivy.to_ivy also applies to this method with minimal changes. Parameters ---------- self The input to be converted. nested Whether to apply the conversion on arguments in a nested manner. If so, all dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is ``False``. include_derived Whether to also recursive for classes derived from tuple, list and dict. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container object with all native sub-arrays converted to their ivy.Array instances. """ return self.static_to_ivy( self, nested, include_derived, key_chains, to_apply, prune_unapplied, map_sequences, out=out, ) #ivy.container.creation # global from typing import Optional, Union, List, Tuple, Dict, Sequence from numbers import Number import numpy as np # local import ivy from ivy.container.base import ContainerBase
[docs]def static_arange( start: Number, /, stop: Optional[Number] = None, step: Number = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "arange", start, stop, step, key_chains, to_apply, prune_unapplied, map_sequences, out, dtype=dtype, device=device, )
[docs]def static_asarray( x: Union[ ivy.Array, ivy.NativeArray, List[Number], Tuple[Number], np.ndarray, ivy.Container, ], /, copy: Optional[bool] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "asarray", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, copy=copy, dtype=dtype, device=device, )
[docs]def static_zeros( shape: Union[int, Sequence[int]], /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "zeros", shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, dtype=dtype, device=device, )
[docs]def static_ones( shape: Union[int, Sequence[int]], /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "ones", shape, key_chains, to_apply, prune_unapplied, map_sequences, out, dtype=dtype, device=device, )
[docs]def static_full_like( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, fill_value: Union[int, float], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.full_like. This method simply wraps the function, and so the docstring for ivy.full_like also applies to this method with minimal changes. Parameters ---------- self input container. fill_value Scalar fill value key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. dtype output array data type. If ``dtype`` is `None`, the output array data type must be inferred from ``self``. Default: ``None``. device device on which to place the created array. If ``device`` is ``None``, the output array device must be inferred from ``self``. Default: ``None``. Returns ------- ret an output container having the same data type as ``x`` and whose elements, relative to ``x``, are shifted. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a = ivy.array([1,2,3]) ,b = ivy.array([4,5,6])) >>> fill_value = 10 >>> y = ivy.Container.static_full_like(fill_value) { a: ivy.array([10, 10, 10]), b: ivy.array([10, 10, 10]) } >>> x = ivy.Container(a=ivy.array([1.2, 2.2324, 3.234]), ... b=ivy.array([4.123, 5.23, 6.23])) >>> fill_value = 15.0 >>> y = ivy.Container.static_full_like(fill_value) >>> print(y) { a: ivy.array([15., 15., 15.]), b: ivy.array([15., 15., 15.]) } """ return ContainerBase.cont_multi_map_in_function( "full_like", x, fill_value, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, dtype=dtype, device=device, )
[docs]def full_like( self: ivy.Container, /, fill_value: Union[int, float], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.full_like. This method simply wraps the function, and so the docstring for ivy.full_like also applies to this method with minimal changes. Parameters ---------- self input container. fill_value Scalar fill value key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. dtype output array data type. If ``dtype`` is `None`, the output array data type must be inferred from ``self``. Default: ``None``. device device on which to place the created array. If ``device`` is ``None``, the output array device must be inferred from ``self``. Default: ``None``. Returns ------- ret an output container having the same data type as ``x`` and whose elements, relative to ``x``, are shifted. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a = ivy.array([1,2,3]) ,b = ivy.array([4,5,6])) >>> fill_value = 10 >>> y = x.full_like(fill_value) { a: ivy.array([10, 10, 10]), b: ivy.array([10, 10, 10]) } >>> x = ivy.Container(a=ivy.array([1.2,2.2324,3.234]), ... b=ivy.array([4.123,5.23,6.23])) >>> fill_value = 15.0 >>> y = x.full_like(fill_value) >>> print(y) { a: ivy.array([15., 15., 15.]), b: ivy.array([15., 15., 15.]) } """ return self.static_full_like( self, fill_value, key_chains, to_apply, prune_unapplied, map_sequences, out=out, dtype=dtype, device=device, )
[docs]def static_ones_like( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.ones_like. This method simply wraps the function, and so the docstring for ivy.ones_like also applies to this method with minimal changes. Parameters ---------- x input array from which to derive the output array shape. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``self``. Default ``None``. device device on which to place the created array. If device is ``None``, the output array device must be inferred from ``self``. Default: ``None``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container having the same shape as ``self`` and filled with ones. """ return ContainerBase.cont_multi_map_in_function( "ones_like", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, dtype=dtype, device=device, )
[docs]def ones_like( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.ones_like. This method simply wraps the function, and so the docstring for ivy.ones_like also applies to this method with minimal changes. Parameters ---------- self input array from which to derive the output array shape. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``self``. Default ``None``. device device on which to place the created array. If device is ``None``, the output array device must be inferred from ``self``. Default: ``None``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container having the same shape as ``self`` and filled with ones. """ return self.static_ones_like( self, key_chains, to_apply, prune_unapplied, map_sequences, out=out, dtype=dtype, device=device, )
[docs]def static_zeros_like( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.zeros_like. This method simply wraps the function, and so the docstring for ivy.zeros_like also applies to this method with minimal changes. Parameters ---------- x input array or container from which to derive the output container shape. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype output array data type. If ``dtype`` is ``None``, the output container data type must be inferred from ``self``. Default ``None``. device device on which to place the created array. If device is ``None``, the output container device must be inferred from ``self``. Default: ``None``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container having the same shape as ``x`` and filled with ``zeros``. """ return ContainerBase.cont_multi_map_in_function( "zeros_like", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, dtype=dtype, device=device, )
[docs]def zeros_like( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.zeros_like. This method simply wraps the function, and so the docstring for ivy.zeros_like also applies to this method with minimal changes. Parameters ---------- self input array or container from which to derive the output container shape. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype output array data type. If ``dtype`` is ``None``, the output container data type must be inferred from ``self``. Default: ``None``. device device on which to place the created array. If device is ``None``, the output container device must be inferred from ``self``. Default: ``None``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container having the same shape as ``x`` and filled with ``zeros``. """ return self.static_zeros_like( self, key_chains, to_apply, prune_unapplied, map_sequences, out=out, dtype=dtype, device=device, )
[docs]def static_tril( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, k: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "tril", x, k, key_chains, to_apply, prune_unapplied, map_sequences, out, )
[docs]def tril( self: ivy.Container, /, k: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_tril( self, k, key_chains, to_apply, prune_unapplied, map_sequences, out=out, )
[docs]def static_triu( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, k: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "triu", x, k, key_chains, to_apply, prune_unapplied, map_sequences, out, )
[docs]def triu( self: ivy.Container, /, k: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_triu( self, k, key_chains, to_apply, prune_unapplied, map_sequences, out=out, )
[docs]def static_empty_like( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "empty_like", x, key_chains, to_apply, prune_unapplied, map_sequences, out, dtype=dtype, device=device, )
[docs]def empty_like( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return self.static_empty_like( self, key_chains, to_apply, prune_unapplied, map_sequences, out=out, dtype=dtype, device=device, )
[docs]def static_eye( n_rows: int, n_cols: Optional[int] = None, /, k: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "eye", n_rows, n_cols, k, key_chains, to_apply, prune_unapplied, map_sequences, out, dtype=dtype, device=device, )
[docs]def static_linspace( start: Union[ivy.Array, ivy.NativeArray, float], stop: Union[ivy.Array, ivy.NativeArray, float], /, num: int, axis: int = None, endpoint: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "linspace", start, stop, num, axis=axis, endpoint=endpoint, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, dtype=dtype, device=device, )
[docs]def linspace( self: ivy.Container, stop: Union[ivy.Array, ivy.NativeArray, float, ivy.Container], /, num: int, axis: int = None, endpoint: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return self.static_linspace( self, stop, num, axis=axis, endpoint=endpoint, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, dtype=dtype, device=device, )
[docs]def static_meshgrid( *arrays: Union[ivy.Array, ivy.NativeArray, List[Number], Tuple[Number]], sparse: bool = False, indexing: str = "xy", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "meshgrid", *arrays, sparse, indexing, key_chains, to_apply, prune_unapplied, map_sequences, )
[docs]def meshgrid( self: ivy.Container, /, *arrays: Union[ivy.Array, ivy.NativeArray, List[Number], Tuple[Number]], sparse: bool = False, indexing: str = "xy", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return self.static_meshgrid( tuple([self] + list(arrays)), sparse, indexing, key_chains, to_apply, prune_unapplied, map_sequences, )
[docs]def static_from_dlpack( x: Union[ivy.Array, ivy.NativeArray], /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "from_dlpack", x, key_chains, to_apply, prune_unapplied, map_sequences, out, )
[docs]def from_dlpack( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_from_dlpack( self, key_chains, to_apply, prune_unapplied, map_sequences, out=out, )
[docs]def static_native_array( x: Union[ ivy.Array, ivy.NativeArray, List[Number], Tuple[Number], np.ndarray, ivy.Container, ], /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "native_array", x, key_chains, to_apply, prune_unapplied, map_sequences, out, dtype=dtype, device=device, )
[docs]def native_array( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return self.static_native_array( self, key_chains, to_apply, prune_unapplied, map_sequences, out=out, dtype=dtype, device=device, )
[docs]def static_logspace( start: Union[ivy.Array, ivy.NativeArray, float, ivy.Container], stop: Union[ivy.Array, ivy.NativeArray, float, ivy.Container], /, num: int, base: float = 10.0, axis: int = 0, endpoint: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.logspace. This method simply wraps the function, and so the docstring for ivy.logspace also applies to this method with minimal changes. Parameters ---------- start Container for first value in the range in log space. stop Container for last value in the range in log space. num Number of values to generate. base The base of the log space. Default is 10.0 axis Axis along which the operation is performed. Relevant only if values in start or stop containers are array-like. Default is 0. endpoint If True, stop is the last sample. Otherwise, it is not included. Default is True. dtype The data type of the output tensor. If None, the dtype of on_value is used or if that is None, the dtype of off_value is used, or if that is None, defaults to float32. Default is None. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Default is None. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Default is None. Returns ------- ret a container having the same shape as ``start`` and filled with tensor of evenly-spaced values in log space. Examples -------- >>> import ivy.container.creation.static_logspace as static_logspace >>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = static_logspace(x, y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) } """ return ContainerBase.cont_multi_map_in_function( "logspace", start, stop, num, base=base, axis=axis, endpoint=endpoint, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, device=device, out=out, )
[docs]def logspace( self: ivy.Container, stop: Union[ivy.Array, ivy.NativeArray, float, ivy.Container], /, num: int, *, base: float = 10.0, axis: int = None, endpoint: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.logspace. This method simply wraps the function, and so the docstring for ivy.logspace also applies to this method with minimal changes. Parameters ---------- self Container for first value in the range in log space. stop Container for last value in the range in log space. num Number of values to generate. base The base of the log space. Default is 10.0 axis Axis along which the operation is performed. Relevant only if values in start or stop containers are array-like. Default is 0. endpoint If True, stop is the last sample. Otherwise, it is not included. Default is True. dtype The data type of the output tensor. If None, the dtype of on_value is used or if that is None, the dtype of off_value is used, or if that is None, defaults to float32. Default is None. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Default is None. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Default is None. Returns ------- ret a container having the same shape as ``self`` and filled with tensor of evenly-spaced values in log space. Examples -------- >>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = x.logspace(y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) } >>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = ivy.logspace(x, y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) } >>> u = ivy.Container(c = 0, d = 0) >>> v = ivy.Container(c = 1, d = 2) >>> x = ivy.Container(a = 1, b = u) >>> y = ivy.Container(a = 4, b = v) >>> z = x.logspace(y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: { c: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) d: ivy.array([ 1., 4.64158883, 21.5443469, 100.]) } } """ return self.static_logspace( self, stop, num, base=base, axis=axis, endpoint=endpoint, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, device=device, out=out, )
[docs]def static_one_hot( indices: ivy.Container, depth: int, /, *, on_value: Optional[Number] = None, off_value: Optional[Number] = None, axis: Optional[int] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.one_hot. This method simply wraps the function, and so the docstring for ivy.one_hot also applies to this method with minimal changes. Parameters ---------- indices Indices for where the ones should be scattered *[batch_shape, dim]* depth Scalar defining the depth of the one-hot dimension. on_value Value to fill in output when indices[j] = i. If None, defaults to 1. off_value Value to fill in output when indices[j] != i. If None, defaults to 0. axis Axis to scatter on. The default is ``-1``, a new inner-most axis is created. dtype The data type of the output tensor. If None, defaults to the on_value dtype or the off_value dtype. If both are None, defaults to float32. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret container with tensors of zeros with the same shape and type as the inputs, unless dtype provided which overrides. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 2]), \ b=ivy.array([3, 1]), c=ivy.array([2, 3])) >>> y = 5 >>> z = ivy.Container.static_one_hot(x, y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([[0., 0., 0., 1., 0.], [0., 1., 0., 0., 0.]]), c: ivy.array([[0., 0., 1., 0., 0.], [0., 0., 0., 1., 0.]]) } >>> x = ivy.Container(a=ivy.array([1, 2]), \ b=ivy.array([]), c=ivy.native_array([4])) >>> y = 5 >>> z = ivy.Container.static_one_hot(x, y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([], shape=(0, 5)), c: ivy.array([[0., 0., 0., 0., 1.]]) } """ return ContainerBase.cont_multi_map_in_function( "one_hot", indices, depth, on_value=on_value, off_value=off_value, axis=axis, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def one_hot( self: ivy.Container, depth: int, /, *, on_value: Optional[Number] = None, off_value: Optional[Number] = None, axis: Optional[int] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.one_hot. This method simply wraps the function, and so the docstring for ivy.one_hot also applies to this method with minimal changes. Parameters ---------- self Indices for where the ones should be scattered *[batch_shape, dim]* depth Scalar defining the depth of the one-hot dimension. on_value Value to fill in output when indices[j] == i. If None, defaults to 1. off_value Value to fill in output when indices[j] != i. If None, defaults to 0. axis Axis to scatter on. The default is ``-1``, a new inner-most axis is created. dtype The dtype of the returned tensor. If None, defaults to the on_value dtype or the off_value dtype. If both are None, defaults to float32. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret container with tensors of zeros with the same shape and type as the inputs, unless dtype provided which overrides. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([1, 2]), \ b=ivy.array([3, 1]), c=ivy.array([2, 3])) >>> y = 5 >>> z = x.one_hot(y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([[0., 0., 0., 1., 0.], [0., 1., 0., 0., 0.]]), c: ivy.array([[0., 0., 1., 0., 0.], [0., 0., 0., 1., 0.]]) } >>> x = ivy.Container(a=ivy.array([1, 2]), \ b=ivy.array([]), c=ivy.native_array([4])) >>> y = 5 >>> z = x.one_hot(y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([], shape=(0, 5)), c: ivy.array([[0., 0., 0., 0., 1.]]) } """ return self.static_one_hot( self, depth, on_value=on_value, off_value=off_value, axis=axis, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.data_type # global from typing import Optional, Union, List, Dict, Tuple, Callable # local import ivy from ivy.container.base import ContainerBase # ToDo: implement all methods here as public instance methods # noinspection PyMissingConstructor
[docs]def static_astype( x: ivy.Container, dtype: ivy.Dtype, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, copy: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """Copies an array to a specified data type irrespective of :ref:`type-promotion` rules. .. note:: Casting floating-point ``NaN`` and ``infinity`` values to integral data types is not specified and is implementation-dependent. .. note:: When casting a boolean input array to a numeric data type, a value of ``True`` must cast to a numeric value equal to ``1``, and a value of ``False`` must cast to a numeric value equal to ``0``. When casting a numeric input array to ``bool``, a value of ``0`` must cast to ``False``, and a non-zero value must cast to ``True``. Parameters ---------- x array to cast. dtype desired data type. copy specifies whether to copy an array when the specified ``dtype`` matches the data type of the input array ``x``. If ``True``, a newly allocated array must always be returned. If ``False`` and the specified ``dtype`` matches the data type of the input array, the input array must be returned; otherwise, a newly allocated must be returned. Default: ``True``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array having the specified data type. The returned array must have the same shape as ``x``. Examples -------- >>> c = ivy.Container(a=ivy.array([False,True,True]), ... b=ivy.array([3.14, 2.718, 1.618])) >>> ivy.Container.static_astype(c, ivy.int32) { a: ivy.array([0, 1, 1]), b: ivy.array([3, 2, 1]) } """ return ContainerBase.cont_multi_map_in_function( "astype", x, dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, copy=copy, out=out, )
[docs]def astype( self: ivy.Container, dtype: ivy.Dtype, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, copy: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """Copies an array to a specified data type irrespective of :ref:`type-promotion` rules. .. note:: Casting floating-point ``NaN`` and ``infinity`` values to integral data types is not specified and is implementation-dependent. .. note:: When casting a boolean input array to a numeric data type, a value of ``True`` must cast to a numeric value equal to ``1``, and a value of ``False`` must cast to a numeric value equal to ``0``. When casting a numeric input array to ``bool``, a value of ``0`` must cast to ``False``, and a non-zero value must cast to ``True``. Parameters ---------- x array to cast. dtype desired data type. copy specifies whether to copy an array when the specified ``dtype`` matches the data type of the input array ``x``. If ``True``, a newly allocated array must always be returned. If ``False`` and the specified ``dtype`` matches the data type of the input array, the input array must be returned; otherwise, a newly allocated must be returned. Default: ``True``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array having the specified data type. The returned array must have the same shape as ``x``. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([False,True,True]), ... b=ivy.array([3.14, 2.718, 1.618])) >>> print(x.astype(ivy.int32)) { a: ivy.array([0, 1, 1]), b: ivy.array([3, 2, 1]) } """ return self.static_astype( self, dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, copy=copy, out=out, )
[docs]def static_broadcast_arrays( *arrays: Union[ivy.Container, ivy.Array, ivy.NativeArray], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` static method variant of `ivy.broadcast_arrays`. This method simply wraps the function, and so the docstring for `ivy.broadcast_arrays` also applies to this method with minimal changes. Parameters ---------- arrays an arbitrary number of arrays to-be broadcasted. Each array must have the same shape. And Each array must have the same dtype as its corresponding input array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A list of containers containing broadcasted arrays Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> x2 = ivy.Container(a=ivy.array([-1.2, 0.4]), b=ivy.array([0, 1])) >>> y = ivy.Container.static_broadcast_arrays(x1, x2) >>> print(y) [{ a: ivy.array([1, 2]), b: ivy.array([3, 4]) }, { a: ivy.array([-1.2, 0.4]), b: ivy.array([0, 1]) }] With mixed :class:`ivy.Container` and :class:`ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([4, 5]), b=ivy.array([2, -1])) >>> x2 = ivy.array([0.2, 3.]) >>> y = ivy.Container.static_broadcast_arrays(x1, x2) >>> print(y) [{ a: ivy.array([4, 5]), b: ivy.array([2, -1]) }, { a: ivy.array([0.2, 3.]), b: ivy.array([0.2, 3.]) }] """ return ContainerBase.cont_multi_map_in_function( "broadcast_arrays", *arrays, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def broadcast_arrays( self: ivy.Container, *arrays: Union[ivy.Container, ivy.Array, ivy.NativeArray], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` instance method variant of `ivy.broadcast_arrays`. This method simply wraps the function, and so the docstring for `ivy.broadcast_arrays` also applies to this method with minimal changes. Parameters ---------- self A container to be broadcatsed against other input arrays. arrays an arbitrary number of containers having arrays to-be broadcasted. Each array must have the same shape. Each array must have the same dtype as its corresponding input array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> x2 = ivy.Container(a=ivy.array([-1.2, 0.4]), b=ivy.array([0, 1])) >>> y = x1.broadcast_arrays(x2) >>> print(y) [{ a: ivy.array([1, 2]), b: ivy.array([3, 4]) }, { a: ivy.array([-1.2, 0.4]), b: ivy.array([0, 1]) }] With mixed :class:`ivy.Container` and :class:`ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([4, 5]), b=ivy.array([2, -1])) >>> x2 = ivy.zeros(2) >>> y = x1.broadcast_arrays(x2) >>> print(y) [{ a: ivy.array([4, 5]), b: ivy.array([2, -1]) }, { a: ivy.array([0., 0.]), b: ivy.array([0., 0.]) }] """ return self.static_broadcast_arrays( self, *arrays, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_broadcast_to( x: ivy.Container, shape: Tuple[int, ...], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ `ivy.Container` static method variant of `ivy.broadcast_to`. This method simply wraps the function, and so the docstring for `ivy.broadcast_to` also applies to this method with minimal changes. Parameters ---------- x input array to be broadcasted. shape desired shape to be broadcasted to. out Optional array to store the broadcasted array. Returns ------- ret Returns the broadcasted array of shape 'shape' Examples -------- With :class:`ivy.Container` static method: >>> x = ivy.Container(a=ivy.array([1]), ... b=ivy.array([2])) >>> y = ivy.Container.static_broadcast_to(x,(3, 1)) >>> print(y) { a: ivy.array([1], [1], [1]), b: ivy.array([2], [2], [2]) } """ return ContainerBase.cont_multi_map_in_function( "broadcast_to", x, shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def broadcast_to( self: ivy.Container, shape: Tuple[int, ...], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ `ivy.Container` instance method variant of `ivy.broadcast_to`. This method simply wraps the function, and so the docstring for `ivy.broadcast_to` also applies to this method with minimal changes. Parameters ---------- self input array to be broadcasted. shape desired shape to be broadcasted to. out Optional array to store the broadcasted array. Returns ------- ret Returns the broadcasted array of shape 'shape' Examples -------- With :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([0, 0.5]), ... b=ivy.array([4, 5])) >>> y = x.broadcast_to((3,2)) >>> print(y) { a: ivy.array([[0., 0.5], [0., 0.5], [0., 0.5]]), b: ivy.array([[4, 5], [4, 5], [4, 5]]) } """ return self.static_broadcast_to( self, shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_can_cast( from_: ivy.Container, to: ivy.Dtype, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` static method variant of `ivy.can_cast`. This method simply wraps the function, and so the docstring for `ivy.can_cast` also applies to this method with minimal changes. Parameters ---------- from_ input container from which to cast. to desired data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret ``True`` if the cast can occur according to :ref:`type-promotion` rules; otherwise, ``False``. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32 >>> print(ivy.Container.static_can_cast(x, 'int64')) { a: false, b: true } """ return ContainerBase.cont_multi_map_in_function( "can_cast", from_, to, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def can_cast( self: ivy.Container, to: ivy.Dtype, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` instance method variant of `ivy.can_cast`. This method simply wraps the function, and so the docstring for `ivy.can_cast` also applies to this method with minimal changes. Parameters ---------- self input container from which to cast. to desired data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret ``True`` if the cast can occur according to :ref:`type-promotion` rules; otherwise, ``False``. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32 >>> print(x.can_cast('int64')) { a: false, b: true } """ return self.static_can_cast( self, to, key_chains, to_apply, prune_unapplied, map_sequences )
[docs]def static_dtype( x: ivy.Container, as_native: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "dtype", x, as_native, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def dtype( self: ivy.Container, as_native: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([2, 3, 4])) >>> y = x.dtype() >>> print(y) { a: int32, b: int32 } """ return self.static_dtype( self, as_native, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_default_float_dtype( *, input: Optional[Union[ivy.Array, ivy.NativeArray]] = None, float_dtype: Optional[Union[ivy.FloatDtype, ivy.NativeDtype]] = None, as_native: Optional[bool] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "default_float_dtype", input=input, float_dtype=float_dtype, as_native=as_native, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_default_complex_dtype( *, input: Optional[Union[ivy.Array, ivy.NativeArray]] = None, complex_dtype: Optional[Union[ivy.FloatDtype, ivy.NativeDtype]] = None, as_native: Optional[bool] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "default_complex_dtype", input=input, complex_dtype=complex_dtype, as_native=as_native, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_function_supported_dtypes( fn: Callable, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "function_supported_dtypes", fn, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_function_unsupported_dtypes( fn: Callable, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "function_unsupported_dtypes", fn, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_finfo( type: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "finfo", type, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def finfo( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return self.static_finfo( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_iinfo( type: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "iinfo", type, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def iinfo( self: ivy.Container, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ Examples -------- >>> c = ivy.Container(x=ivy.array([-9,1800,89], dtype=ivy.int16), ... y=ivy.array([76,-81,16], dtype=ivy.int32)) >>> c.iinfo() { x: iinfo(min=-32768, max=32767, dtype=int16), y: iinfo(min=-2147483648, max=2147483647, dtype=int32) } """ return self.static_iinfo( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_is_bool_dtype( dtype_in: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "is_bool_dtype", dtype_in, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_bool_dtype( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return self.static_is_bool_dtype( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_is_float_dtype( dtype_in: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` static method variant of `is_float_dtype`. This method simply wraps this function, so the docstring of `is_float_dtype` roughly applies to this method. Parameters ---------- dtype_in : ivy.Container The input to check for float dtype. key_chains : Optional[Union[List[str], Dict[str, str]]] The key chains to use when mapping over the input. to_apply : bool Whether to apply the mapping over the input. prune_unapplied : bool Whether to prune the keys that were not applied. map_sequences : bool Boolean indicating whether to map method to sequences (list, tuple). Default is ``False``. Returns ------- ret : bool Boolean indicating whether the input has float dtype. Examples -------- >>> x = ivy.static_is_float_dtype(ivy.float32) >>> print(x) True >>> x = ivy.static_is_float_dtype(ivy.int64) >>> print(x) False >>> x = ivy.static_is_float_dtype(ivy.int32) >>> print(x) False >>> x = ivy.static_is_float_dtype(ivy.bool) >>> print(x) False >>> arr = ivy.array([1.2, 3.2, 4.3], dtype=ivy.float32) >>> print(arr.is_float_dtype()) True >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32 """ return ContainerBase.cont_multi_map_in_function( "is_float_dtype", dtype_in, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_float_dtype( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` instance method variant of `ivy.is_float_dtype`. This method simply wraps the function, and so the docstring for `ivy.is_float_dtype` also applies to this method with minimal changes. Parameters ---------- self : ivy.Container The `ivy.Container` instance to call `ivy.is_float_dtype` on. key_chains : Union[List[str], Dict[str, str]] The key-chains to apply or not apply the method to. Default is ``None``. to_apply : bool Boolean indicating whether to apply the method to the key-chains. Default is ``False``. prune_unapplied : bool Boolean indicating whether to prune the key-chains that were not applied. Default is ``False``. map_sequences : bool Boolean indicating whether to map method to sequences (list, tuple). Default is ``False``. Returns ------- ret : bool Boolean of whether the input is of a float dtype. Examples -------- >>> x = ivy.is_float_dtype(ivy.float32) >>> print(x) True >>> x = ivy.is_float_dtype(ivy.int64) >>> print(x) False >>> x = ivy.is_float_dtype(ivy.int32) >>> print(x) False >>> x = ivy.is_float_dtype(ivy.bool) >>> print(x) False >>> arr = ivy.array([1.2, 3.2, 4.3], dtype=ivy.float32) >>> print(arr.is_float_dtype()) True >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32 """ return self.static_is_float_dtype( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_is_int_dtype( dtype_in: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "is_int_dtype", dtype_in, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_int_dtype( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return self.static_is_int_dtype( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_is_uint_dtype( dtype_in: ivy.Container, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "is_uint_dtype", dtype_in, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_uint_dtype( self: ivy.Container, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: return self.static_is_uint_dtype( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_is_complex_dtype( dtype_in: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` static method variant of `is_complex_dtype`. This method simply wraps this function, so the docstring of `is_complex_dtype` roughly applies to this method. Parameters ---------- dtype_in : ivy.Container The input to check for complex dtype. key_chains : Optional[Union[List[str], Dict[str, str]]] The key chains to use when mapping over the input. to_apply : bool Whether to apply the mapping over the input. prune_unapplied : bool Whether to prune the keys that were not applied. map_sequences : bool Boolean indicating whether to map method to sequences (list, tuple). Default is ``False``. Returns ------- ret : bool Boolean indicating whether the input has float dtype. Examples -------- >>> x = ivy.Container.static_is_complex_dtype(ivy.complex64) >>> print(x) True >>> x = ivy.Container.static_is_complex_dtype(ivy.int64) >>> print(x) False >>> x = ivy.Container.static_is_complex_dtype(ivy.float32) >>> print(x) False """ return ContainerBase.cont_multi_map_in_function( "is_complex_dtype", dtype_in, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_complex_dtype( self: ivy.Container, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` instance method variant of `ivy.is_complex_dtype`. This method simply wraps the function, and so the docstring for `ivy.is_complex_dtype` also applies to this method with minimal changes. Parameters ---------- self : ivy.Container The `ivy.Container` instance to call `ivy.is_complex_dtype` on. key_chains : Union[List[str], Dict[str, str]] The key-chains to apply or not apply the method to. Default is ``None``. to_apply : bool Boolean indicating whether to apply the method to the key-chains. Default is ``False``. prune_unapplied : bool Boolean indicating whether to prune the key-chains that were not applied. Default is ``False``. map_sequences : bool Boolean indicating whether to map method to sequences (list, tuple). Default is ``False``. Returns ------- ret : bool Boolean of whether the input is of a complex dtype. Examples -------- >>> x = ivy.is_complex_dtype(ivy.complex64) >>> print(x) True >>> x = ivy.is_complex_dtype(ivy.int64) >>> print(x) False >>> x = ivy.is_complex_dtype(ivy.float32) >>> print(x) False """ return self.static_is_complex_dtype( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_result_type( *arrays_and_dtypes: ivy.Container, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` static method variant of `ivy.result_type`. This method simply wraps the function, and so the docstring for `ivy.result_type` also applies to this method with minimal changes. Parameters ---------- self input container from which to cast. arrays_and_dtypes an arbitrary number of input arrays and/or dtypes. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret the dtype resulting from an operation involving the input arrays and dtypes. Examples -------- >>> x = ivy.Container(a = ivy.array([0, 1, 2]), ... b = ivy.array([3., 4., 5.])) >>> print(x.a.dtype, x.b.dtype) int32 float32 >>> print(ivy.Container.static_result_type(x, ivy.float64)) { a: float64, b: float32 } """ return ContainerBase.cont_multi_map_in_function( "result_type", *arrays_and_dtypes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def result_type( self: ivy.Container, *arrays_and_dtypes: ivy.Container, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ `ivy.Container` instance method variant of `ivy.result_type`. This method simply wraps the function, and so the docstring for `ivy.result_type` also applies to this method with minimal changes. Parameters ---------- self input container from which to cast. arrays_and_dtypes an arbitrary number of input arrays and/or dtypes. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret the dtype resulting from an operation involving the input arrays and dtypes. Examples -------- >>> x = ivy.Container(a = ivy.array([3, 3, 3])) >>> print(x.a.dtype) int32 >>> y = ivy.Container(b = ivy.float64) >>> print(x.result_type(y)) { a: { b: float64 } } """ return self.static_result_type( self, *arrays_and_dtypes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
#ivy.container.device # local from typing import Union, Optional, Any, List, Dict import ivy from ivy.container.base import ContainerBase # ToDo: implement all methods here as public instance methods
[docs]def static_dev(x: ivy.Container, /, *, as_native: bool = False) -> ivy.Container: """ ivy.Container static method variant of ivy.dev. This method simply wraps the function, and so the docstring for ivy.dev also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=ivy.array([[2, 3], [3, 5]]), ... b=ivy.native_array([1, 2, 4, 5, 7])) >>> as_native = ivy.Container(a=True, b=False) >>> y = ivy.Container.static_dev(x, as_native=as_native) >>> print(y) { a: device(type=cpu), b: cpu } """ return ContainerBase.cont_multi_map_in_function("dev", x, as_native=as_native)
[docs]def dev(self: ivy.Container, as_native: bool = False) -> ivy.Container: """ ivy.Container instance method variant of ivy.dev. This method simply wraps the function, and so the docstring for ivy.dev also applies to this method with minimal changes. Parameters ---------- self contaioner of arrays for which to get the device handle. as_native Whether or not to return the dev in native format. Default is ``False``. Examples -------- >>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]), ... b=ivy.native_array([[1, 2], [4, 5]])) >>> as_native = ivy.Container(a=False, b=True) >>> y = x.dev(as_native=as_native) >>> print(y) { a:cpu, b:cpu } """ return self.static_dev(self, as_native=as_native)
[docs]def static_to_device( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], device: Union[ivy.Device, ivy.NativeDevice], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, stream: Optional[Union[int, Any]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.to_device. This method simply wraps the function, and so the docstring for ivy.to_device also applies to this method with minimal changes. Parameters ---------- x input array to be moved to the desired device device device to move the input array `x` to key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. stream stream object to use during copy. In addition to the types supported in array.__dlpack__(), implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret input array x placed on the desired device Examples -------- >>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]), ... b=ivy.native_array([[1, 2], [4, 5]])) >>> y = ivy.Container.static_to_device(x, 'cpu') >>> print(y.a.device, y.b.device) cpu cpu """ return ContainerBase.cont_multi_map_in_function( "to_device", x, device, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, stream=stream, out=out, )
[docs]def to_device( self: ivy.Container, device: Union[ivy.Device, ivy.NativeDevice], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, stream: Optional[Union[int, Any]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.to_device. This method simply wraps the function, and so the docstring for ivy.to_device also applies to this method with minimal changes. Parameters ---------- x input array to be moved to the desired device device device to move the input array `x` to key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. stream stream object to use during copy. In addition to the types supported in array.__dlpack__(), implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret input array x placed on the desired device Examples -------- >>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]), ... b=ivy.native_array([[1, 2], [4, 5]])) >>> y = x.to_device('cpu') >>> print(y.a.device, y.b.device) cpu cpu """ return self.static_to_device( self, device, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, stream=stream, out=out, )
#ivy.container.elementwise # global from typing import Optional, Union, List, Dict # local import ivy from ivy.container.base import ContainerBase
[docs]def static_abs( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.abs. This method simply wraps the function, and so the docstring for ivy.abs also applies to this method with minimal changes. Parameters ---------- x input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the absolute value of each element in ``x``. The returned container must have the same data type as ``x``. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), ... b=ivy.array([4.5, -5.3, -0, -2.3])) >>> y = ivy.Container.static_abs(x) >>> print(y) { a: ivy.array([0., 2.6, 3.5]), b: ivy.array([4.5, 5.3, 0, 2.3]) } """ return ContainerBase.cont_multi_map_in_function( "abs", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def abs( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.abs. This method simply wraps the function, and so the docstring for ivy.abs also applies to this method with minimal changes. Parameters ---------- self input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the absolute value of each element in ``self``. The returned container must have the same data type as ``self``. Examples -------- >>> x = ivy.Container(a=ivy.array([-1.6, 2.6, -3.5]), ... b=ivy.array([4.5, -5.3, -2.3])) >>> y = x.abs() >>> print(y) { a: ivy.array([1.6, 2.6, 3.5]), b: ivy.array([4.5, 5.3, 2.3]) } """ return self.static_abs( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_acosh( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cosh. This method simply wraps the function, and so the docstring for ivy.cosh also applies to this method with minimal changes. Parameters ---------- x input container whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse hyperbolic cosine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1., 2., 3, 4]), ... b=ivy.array([1., 3., 10.0, 6])) >>> y = ivy.Container.static_acosh(x) >>> print(y) { a: ivy.array([0., 1.32, 1.76, 2.06]), b: ivy.array([0., 1.76, 2.99, 2.48]) } """ return ContainerBase.cont_multi_map_in_function( "acosh", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def acosh( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.acosh. This method simply wraps the function, and so the docstring for ivy.acosh also applies to this method with minimal changes. Parameters ---------- self input container whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse hyperbolic cosine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1., 2., 3, 4]), ... b=ivy.array([1., 3., 10.0, 6])) >>> y = x.acosh() >>> print(y) { a: ivy.array([0., 1.32, 1.76, 2.06]), b: ivy.array([0., 1.76, 2.99, 2.48]) } """ return self.static_acosh( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_acos( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.acos. This method simply wraps the function, and so the docstring for ivy.acos also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse cosine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -1.])) >>> y = ivy.Container.static_acos(x) >>> print(y) { a: ivy.array([1.57, 3.14, 0.]), b: ivy.array([0., 1.57, 3.14]) } """ return ContainerBase.cont_multi_map_in_function( "acos", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_add( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, alpha: Optional[Union[int, float]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.add. This method simply wraps the function, and so the docstring for ivy.add also applies to this method with minimal changes. Parameters ---------- x1 first input array or container. Should have a numeric data type. x2 second input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. alpha scalar multiplier for ``x2``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise sums. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.array([[1.1, 2.3, -3.6]]) >>> y = ivy.Container(a=ivy.array([[4.], [5.], [6.]]), ... b=ivy.array([[5.], [6.], [7.]])) >>> z = ivy.Container.static_add(x, y) >>> print(z) { a: ivy.array([[5.1, 6.3, 0.4], [6.1, 7.3, 1.4], [7.1, 8.3, 2.4]]), b: ivy.array([[6.1, 7.3, 1.4], [7.1, 8.3, 2.4], [8.1, 9.3, 3.4]]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_add(x, y) >>> print(z) { a: ivy.array([5, 7, 9]), b: ivy.array([7, 9, 11]) } >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_add(x, y, alpha=2) >>> print(z) { a: ivy.array([9, 12, 15]), b: ivy.array([12, 15, 18]) } """ return ContainerBase.cont_multi_map_in_function( "add", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, alpha=alpha, out=out, )
[docs]def acos( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.acos. This method simply wraps the function, and so the docstring for ivy.acos also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse cosine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -1.])) >>> y = x.acos() >>> print(y) { a: ivy.array([1.57, 3.14, 0.]), b: ivy.array([0., 1.57, 3.14]) } """ return self.static_acos( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def add( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, alpha: Optional[Union[int, float]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.add. This method simply wraps the function, and so the docstring for ivy.add also applies to this method with minimal changes. Parameters ---------- self first input container. Should have a numeric data type. x2 second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. alpha scalar multiplier for ``x2``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise sums. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = x.add(y) >>> print(z) { a: ivy.array([5, 7, 9]), b: ivy.array([7, 9, 11]) } >>> z = x.add(y, alpha=3) >>> print(z) { a: ivy.array([13, 17, 21]), b: ivy.array([17, 21, 25]) } """ return self.static_add( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, alpha=alpha, out=out, )
[docs]def static_asin( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.asin. This method simply wraps the function, and so the docstring for ivy.asin also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse sine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., -0.5, -1.]), ... b=ivy.array([0.1, 0.8, 2.])) >>> y = ivy.Container.static_asin() >>> print(y) { a: ivy.array([0., -0.524, -1.57]), b: ivy.array([0.1, 0.927, nan]) } >>> x = ivy.Container(a=ivy.array([0.4, 0.9, -0.9]), ... b=ivy.array([[4, -3, -0.2])) >>> y = ivy.Container(a=ivy.zeros(3), b=ivy.zeros(3)) >>> ivy.Container.static_asin(out=y) >>> print(y) { a: ivy.array([0.412, 1.12, -1.12]), b: ivy.array([nan, nan, -0.201]) } """ return ContainerBase.cont_multi_map_in_function( "asin", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def asin( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.asin. This method simply wraps the function, and so the docstring for ivy.asin also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse sine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 0.5, 1.]), ... b=ivy.array([-4., 0.8, 2.])) >>> y = x.asin() >>> print(y) { a: ivy.array([0., 0.524, 1.57]), b: ivy.array([nan, 0.927, nan]) } >>> x = ivy.Container(a=ivy.array([12., 1.5, 0.]), ... b=ivy.array([-0.85, 0.6, 0.3])) >>> y = ivy.Container(a=ivy.zeros(3), b=ivy.zeros(3)) >>> x.asin(out=y) >>> print(y) { a: ivy.array([nan, nan, 0.]), b: ivy.array([-1.02, 0.644, 0.305]) } """ return self.static_asin( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_asinh( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.asinh. This method simply wraps the function, and so the docstring for ivy.asinh also applies to this method with minimal changes. Parameters ---------- x input container whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse hyperbolic sine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1.5, 0., -3.5]), ... b=ivy.array([3.4, -5.3, -0, -2.8])) >>> y = ivy.Container.static_asinh(x) >>> print(y) { a: ivy.array([1.19, 0., -1.97]), b: ivy.array([1.94, -2.37, 0., -1.75]) } """ return ContainerBase.cont_multi_map_in_function( "asinh", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def asinh( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.asinh. This method simply wraps the function, and so the docstring for ivy.asinh also applies to this method with minimal changes. Parameters ---------- self input container whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse hyperbolic sine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([-1, 3.7, -5.1]), ... b=ivy.array([4.5, -2.4, -1.5])) >>> y = x.asinh() >>> print(y) { a: ivy.array([-0.881, 2.02, -2.33]), b: ivy.array([2.21, -1.61, -1.19]) } """ return self.static_asinh( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_atan( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.atan. This method simply wraps the function, and so the docstring for ivy.atan also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse tangent of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -6])) >>> y = ivy.Container.static_atan(x) >>> print(y) { a: ivy.array([0., -0.785, 0.785]), b: ivy.array([0.785, 0., -1.41]) } """ return ContainerBase.cont_multi_map_in_function( "atan", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def atan( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.atan. This method simply wraps the function, and so the docstring for ivy.atan also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse tangent of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -6])) >>> y = x.atan() >>> print(y) { a: ivy.array([0., -0.785, 0.785]), b: ivy.array([0.785, 0., -1.41]) } """ return self.static_atan( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_atan2( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.atan2. This method simply wraps the function, and so the docstring for ivy.atan2 also applies to this method with minimal changes. Parameters ---------- x1 first input array or container corresponding to the y-coordinates. Should have a real-valued floating-point data type. x2 second input array or container corresponding to the x-coordinates. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse tangent of the quotient ``x1/x2``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), ... b=ivy.array([4.5, -5.3, -0])) >>> y = ivy.array([3.0, 2.0, 1.0]) >>> ivy.Container.static_atan2(x, y) { a: ivy.array([0., 0.915, -1.29]), b: ivy.array([0.983, -1.21, 0.]) } >>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), ... b=ivy.array([4.5, -5.3, -0, -2.3])) >>> y = ivy.Container(a=ivy.array([-2.5, 1.75, 3.5]), ... b=ivy.array([2.45, 6.35, 0, 1.5])) >>> z = ivy.Container.static_atan2(x, y) >>> print(z) { a: ivy.array([3.14, 0.978, -0.785]), b: ivy.array([1.07, -0.696, 0., -0.993]) } """ return ContainerBase.cont_multi_map_in_function( "atan2", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def atan2( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.atan2. This method simply wraps the function, and so the docstring for ivy.atan2 also applies to this method with minimal changes. Parameters ---------- self first input array or container corresponding to the y-coordinates. Should have a real-valued floating-point data type. x2 second input array or container corresponding to the x-coordinates. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse tangent of the quotient ``self/x2``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), ... b=ivy.array([4.5, -5.3, -0])) >>> y = ivy.array([3.0, 2.0, 1.0]) >>> x.atan2(y) { a: ivy.array([0., 0.915, -1.29]), b: ivy.array([0.983, -1.21, 0.]) } >>> x = ivy.Container(a=ivy.array([0., 2.6, -3.5]), ... b=ivy.array([4.5, -5.3, -0, -2.3])) >>> y = ivy.Container(a=ivy.array([-2.5, 1.75, 3.5]), ... b=ivy.array([2.45, 6.35, 0, 1.5])) >>> z = x.atan2(y) >>> print(z) { a: ivy.array([3.14, 0.978, -0.785]), b: ivy.array([1.07, -0.696, 0., -0.993]) } """ return self.static_atan2( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_atanh( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.atanh. This method simply wraps the function, and so the docstring for ivy.atanh also applies to this method with minimal changes. Parameters ---------- x input container whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse hyperbolic tangent of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 0.5, -0.5]), b=ivy.array([0., 0.2, 0.9])) >>> y = ivy.Container.static_atanh(x) >>> print(y) { a: ivy.array([0., 0.549, -0.549]), b: ivy.array([0., 0.203, 1.47]) } """ return ContainerBase.cont_multi_map_in_function( "atanh", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def atanh( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.atanh. This method simply wraps the function, and so the docstring for ivy.atanh also applies to this method with minimal changes. Parameters ---------- self input container whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the inverse hyperbolic tangent of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 0.5, -0.5]), b=ivy.array([0., 0.2, 0.9])) >>> y = x.atanh() >>> print(y) { a: ivy.array([0., 0.549, -0.549]), b: ivy.array([0., 0.203, 1.47]) } """ return self.static_atanh( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_bitwise_and( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.bitwise_and. This method simply wraps the function, and so the docstring for ivy.bitwise_and also applies to this method with minimal changes. Parameters ---------- x1 first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.array([1, 2, 3]) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_bitwise_and(x, y) >>> print(z) { a: ivy.array([0, 0, 2]), b: ivy.array([1, 2, 3]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_bitwise_and(x, y) >>> print(z) { a: ivy.array([0, 0, 2]), b: ivy.array([0, 2, 4]) } """ return ContainerBase.cont_multi_map_in_function( "bitwise_and", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def bitwise_and( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.bitwise_and. This method simply wraps the function, and so the docstring for ivy.bitwise_and also applies to this method with minimal changes. Parameters ---------- self first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``self`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([True, True]), b=ivy.array([False, True])) >>> y = ivy.Container(a=ivy.array([False, True]), b=ivy.array([False, True])) >>> x.bitwise_and(y, out=y) >>> print(y) { a: ivy.array([False, True]), b: ivy.array([False, True]) } """ return self.static_bitwise_and( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_bitwise_left_shift( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.bitwise_left_shift. This method simply wraps the function, and so the docstring for ivy.bitwise_left_shift also applies to this method with minimal changes. Parameters ---------- x1 first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. """ return ContainerBase.cont_multi_map_in_function( "bitwise_left_shift", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def bitwise_left_shift( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.bitwise_left_shift. This method simply wraps the function, and so the docstring for ivy.bitwise_left_shift also applies to this method with minimal changes. Parameters ---------- self first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``self`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. """ return self.static_bitwise_left_shift( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_bitwise_invert( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.bitwise_invert. This method simply wraps the function, and so the docstring for ivy.bitwise_invert also applies to this method with minimal changes. Parameters ---------- x input container. Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned array must have the same data type as ``x``. Examples -------- >>> x = ivy.Container(a=[False, True, False], b=[True, True, False]) >>> y = ivy.Container.static_bitwise_invert(x) >>> print(y) { a: ivy.array([True, False, True]), b: ivy.array([False, False, True]) } >>> x = ivy.Container(a=[1, 2, 3], b=[4, 5, 6]) >>> y = ivy.Container.static_bitwise_invert(x) >>> print(y) { a: ivy.array([-2, -3, -4]), b: ivy.array([-5, -6, -7]) } """ return ContainerBase.cont_multi_map_in_function( "bitwise_invert", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def bitwise_invert( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.bitwise_invert. This method simply wraps the function, and so the docstring for ivy.bitwise_invert also applies to this method with minimal changes. Parameters ---------- self input container. Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned array must have the same data type as ``self``. Examples -------- >>> x = ivy.Container(a=[False, True, False], b=[True, True, False]) >>> y = x.bitwise_invert() >>> print(y) { a: ivy.array([True, False, True]), b: ivy.array([False, False, True]) } >>> x = ivy.Container(a=[1, 2, 3], b=[4, 5, 6]) >>> y = x.bitwise_invert() >>> print(y) { a: ivy.array([-2, -3, -4]), b: ivy.array([-5, -6, -7]) } """ return self.static_bitwise_invert( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_cos( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cos. This method simply wraps the function, and so the docstring for ivy.cos also applies to this method with minimal changes. Parameters ---------- x input container whose elements are each expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the cosine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -6])) >>> y = ivy.Container.static_cos(x) >>> print(y) { a: ivy.array([1., 0.54, 0.54]), b: ivy.array([0.54, 1., 0.96]) } """ return ivy.ContainerBase.cont_multi_map_in_function( "cos", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def cos( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.cos. This method simply wraps the function, and so the docstring for ivy.cos also applies to this method with minimal changes. Parameters ---------- self input container whose elements are each expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the cosine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., -1, 1]), b=ivy.array([1., 0., -6])) >>> y = x.cos() >>> print(y) { a: ivy.array([1., 0.54, 0.54]), b: ivy.array([0.54, 1., 0.96]) } """ return self.static_cos( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_bitwise_or( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.bitwise_or. This method simply wraps the function, and so the docstring for ivy.bitwise_or also applies to this method with minimal changes. Parameters ---------- x input container. Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned array must have the same data type as ``x``. Examples -------- With one :class:`ivy.Container` input: >>> y = ivy.array([1, 2, 3]) >>> x = ivy.Container(a=ivy.array([4, 5, 6])) >>> z = ivy.Container.static_bitwise_or(x, y) >>> print(z) { a: ivy.array([5, 7, 7]), } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_bitwise_or(x, y) >>> print(z) { a: ivy.array([5, 7, 7]), b: ivy.array([7, 7, 7]) } """ return ContainerBase.cont_multi_map_in_function( "bitwise_or", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def bitwise_or( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.bitwise_or. This method simply wraps the function, and so the docstring for ivy.bitwise_or also applies to this method with minimal changes. Parameters ---------- self input container. Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned array must have the same data type as ``self``. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([5, 6, 7])) >>> z = x.bitwise_or(y) >>> print(z) { a: ivy.array([5, 7, 7]), b: ivy.array([7, 7, 7]) } """ return self.static_bitwise_or( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_bitwise_right_shift( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.bitwise_right_shift. This method simply wraps the function, and so the docstring for ivy.bitwise_right_shift also applies to this method with minimal changes. Parameters ---------- x1 first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With one :class:`ivy.Container` input: >>> a = ivy.Container(a = ivy.array([2, 3, 4]), b = ivy.array([5, 10, 64])) >>> b = ivy.array([0, 1, 2]) >>> y = ivy.Container.static_bitwise_right_shift(a, b) >>> print(y) { a: ivy.array([2, 1, 1]), b: ivy.array([5, 5, 16]) } With multiple :class:`ivy.Container` inputs: >>> a = ivy.Container(a = ivy.array([2, 3, 4]), b = ivy.array([5, 10, 64])) >>> b = ivy.Container(a = ivy.array([0, 1, 2]), b = ivy.array([2])) >>> y = ivy.Container.static_bitwise_right_shift(a, b) >>> print(y) { a: ivy.array([2, 1, 1]), b: ivy.array([1, 2, 16]) } """ return ContainerBase.cont_multi_map_in_function( "bitwise_right_shift", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def bitwise_right_shift( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.bitwise_right_shift. This method simply wraps the function, and so the docstring for ivy.bitwise_right_shift also applies to this method with minimal changes. Parameters ---------- self first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``self`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- >>> a = ivy.Container(a = ivy.array([2, 3, 4]), b = ivy.array([5, 10, 64])) >>> b = ivy.Container(a = ivy.array([0, 1, 2]), b = ivy.array([2])) >>> y = a.bitwise_right_shift(b) >>> print(y) { a: ivy.array([2, 1, 1]), b: ivy.array([1, 2, 16]) } """ return self.static_bitwise_right_shift( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_bitwise_xor( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.bitwise_xor. This method simply wraps the function, and so the docstring for ivy.bitwise_xor also applies to this method with minimal changes. Parameters ---------- x1 first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a = ivy.array([89]), b = ivy.array([3])) >>> y = ivy.Container(a = ivy.array([12]), b = ivy.array([5])) >>> z = ivy.Container.static_bitwise_xor(x, y) >>> print(z) { a: ivy.array([85]), b: ivy.array([6]) } """ return ContainerBase.cont_multi_map_in_function( "bitwise_xor", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def bitwise_xor( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.bitwise_xor. This method simply wraps the function, and so the docstring for ivy.bitwise_xor also applies to this method with minimal changes. Parameters ---------- self first input array or container. Should have an integer or boolean data type. x2 second input array or container Must be compatible with ``self`` (see :ref:`broadcasting`). Should have an integer or boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a = ivy.array([89]), b = ivy.array([3])) >>> y = ivy.Container(a = ivy.array([12]), b = ivy.array([5])) >>> z = x.bitwise_xor(y) >>> print(z) { a: ivy.array([85]), b: ivy.array([6]) } """ return self.static_bitwise_xor( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_ceil( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.ceil. This method simply wraps the function, and so the docstring for ivy.ceil also applies to this method with minimal changes. Parameters ---------- x input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container containing the rounded result for each element in ``x``. The returned array must have the same data type as ``x``. Examples -------- >>> x = ivy.Container(a=ivy.array([2.5, 0.5, -1.4]), ... b=ivy.array([5.4, -3.2, 5.2])) >>> y = ivy.Container.static_ceil(x) >>> print(y) { a: ivy.array([3., 1., -1.]), b: ivy.array([6., -3., 6.]) } """ return ContainerBase.cont_multi_map_in_function( "ceil", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def ceil( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.ceil. This method simply wraps the function, and so the docstring for ivy.ceil also applies to this method with minimal changes. Parameters ---------- self input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container containing the rounded result for each element in ``self``. The returned container must have the same data type as ``self``. Examples -------- >>> x = ivy.Container(a=ivy.array([2.5, 0.5, -1.4]), ... b=ivy.array([5.4, -3.2, 5.2])) >>> y = x.ceil() >>> print(y) { a: ivy.array([3., 1., -1.]), b: ivy.array([6., -3., 6.]) } """ return self.static_ceil( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_cosh( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cosh. This method simply wraps the function, and so the docstring for ivy.cosh also applies to this method with minimal changes. Parameters ---------- x input container whose elements each represent a hyperbolic angle. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container containing the hyperbolic cosine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, 0.23, 1.12]), b=ivy.array([1, -2, 0.76])) >>> y = ivy.Container.static_cosh(x) >>> print(y) { a: ivy.array([1.54, 1.03, 1.7]), b: ivy.array([1.54, 3.76, 1.3]) } >>> x = ivy.Container(a=ivy.array([-3, 0.34, 2.]), ... b=ivy.array([0.67, -0.98, -3])) >>> y = ivy.Container(a=ivy.zeros(1), b=ivy.zeros(1)) >>> ivy.Container.static_cosh(x, out=y) >>> print(y) { a: ivy.array([10.1, 1.06, 3.76]), b: ivy.array([1.23, 1.52, 10.1]) } """ return ContainerBase.cont_multi_map_in_function( "cosh", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def cosh( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.cosh. This method simply wraps the function, and so the docstring for ivy.cosh also applies to this method with minimal changes. Parameters ---------- self input container whose elements each represent a hyperbolic angle. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container containing the hyperbolic cosine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, 0.23, 1.12]), b=ivy.array([1, -2, 0.76])) >>> y = x.cosh() >>> print(y) { a: ivy.array([1.54, 1.03, 1.7]), b: ivy.array([1.54, 3.76, 1.3]) } >>> x = ivy.Container(a=ivy.array([-3, 0.34, 2.]), ... b=ivy.array([0.67, -0.98, -3])) >>> y = ivy.Container(a=ivy.zeros(3), b=ivy.zeros(3)) >>> x.cosh(out=y) >>> print(y) { a: ivy.array([10.1, 1.06, 3.76]), b: ivy.array([1.23, 1.52, 10.1]) } """ return self.static_cosh( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_divide( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.divide. This method simply wraps the function, and so the docstring for ivy.divide also applies to this method with minimal changes. Parameters ---------- x1 dividend input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.Container(a=ivy.array([1., 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = ivy.Container.static_divide(x1, x2) >>> print(y) { a: ivy.array([12., 1.52, 2.1]), b: ivy.array([1.25, 0.333, 0.45]) } """ return ContainerBase.cont_multi_map_in_function( "divide", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def divide( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.divide. This method simply wraps the function, and so the docstring for ivy.divide also applies to this method with minimal changes. Parameters ---------- self dividend input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.Container(a=ivy.array([1., 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = x1.divide(x2) >>> print(y) { a: ivy.array([12., 1.52, 2.1]), b: ivy.array([1.25, 0.333, 0.45]) } With :code:`Number` instances at the leaves: >>> x = ivy.Container(a=1, b=2) >>> y = ivy.Container(a=5, b=4) >>> z = x.divide(y) >>> print(z) { a: 0.2, b: 0.5 } """ return self.static_divide( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_equal( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.equal. This method simply wraps the function, and so the docstring for ivy.equal also applies to this method with minimal changes. Parameters ---------- x1 input array or container. May have any data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). May have any data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12, 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.Container(a=ivy.array([12, 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = ivy.Container.static_equal(x1, x2) >>> print(y) { a: ivy.array([True, False, False]), b: ivy.array([False, False, False]) } """ return ContainerBase.cont_multi_map_in_function( "equal", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def equal( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.equal. This method simply wraps the function, and so the docstring for ivy.equal also applies to this method with minimal changes. Parameters ---------- x1 input array or container. May have any data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). May have any data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12, 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.Container(a=ivy.array([12, 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = x1.equal(x2) >>> print(y) { a: ivy.array([True, False, False]), b: ivy.array([False, False, False]) } With mixed :class:`ivy.Container` and :class:`ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.array([3., 1., 0.9]) >>> y = x1.equal(x2) >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) } """ return self.static_equal( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_exp( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.exp. This method simply wraps the function, and so the docstring for ivy.exp also applies to this method with minimal changes. Parameters ---------- x input container. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1., 2.,]), b=ivy.array([4., 5.])) >>> y = ivy.Container.static_exp(x) >>> print(y) { a: ivy.array([2.71828198, 7.38905573]), b: ivy.array([54.59814835, 148.4131622]) } """ return ContainerBase.cont_multi_map_in_function( "exp", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def exp( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.exp. This method simply wraps the function, and so the docstring for ivy.exp also applies to this method with minimal changes. Parameters ---------- self input container. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``self``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([4., 5., 6.])) >>> y = x.exp() >>> print(y) { a: ivy.array([2.71828198, 7.38905573, 20.08553696]), b: ivy.array([54.59814835, 148.4131622, 403.428772]) } """ return self.static_exp( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_expm1( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.expm1. This method simply wraps thefunction, and so the docstring for ivy.expm1 also applies to this method with minimal changes. Parameters ---------- x input container. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``x``. The returned array must have areal-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` static method: >>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> print(ivy.Container.static_expm1(x)) { a: ivy.array([1.71828175, 6.38905621]), b: ivy.array([19.08553696, 53.59815216]) } """ return ContainerBase.cont_multi_map_in_function( "expm1", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def expm1( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.expm1. This method simply wraps the function, and so the docstring for ivy.expm1 also applies to this method with minimal changes. Parameters ---------- self input container. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``self``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([2.5, 0.5]), ... b=ivy.array([5.4, -3.2])) >>> y = x.expm1() >>> print(y) { a: ivy.array([11.2, 0.649]), b: ivy.array([220., -0.959]) } >>> y = ivy.Container(a=ivy.array([0., 0.])) >>> x = ivy.Container(a=ivy.array([4., -2.])) >>> x.expm1(out=y) >>> print(y) { a: ivy.array([53.6, -0.865]) } """ return self.static_expm1( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_floor( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.floor. This method simply wraps thefunction, and so the docstring for ivy.floor also applies to this method with minimal changes. Parameters ---------- x input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the rounded result for each element in ``x``. The returned array must have the same data type as ``x``. Examples -------- >>> x = ivy.Container(a=ivy.array([2.5, 0.5, -1.4]), ... b=ivy.array([5.4, -3.2, 5.2])) >>> y = ivy.Container.static_floor(x) >>> print(y) { a: ivy.array([2., 0., -2.]), b: ivy.array([5., -4., 5.]) } """ return ContainerBase.cont_multi_map_in_function( "floor", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def floor( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.floor. This method simply wraps the function, and so the docstring for ivy.floor also applies to this method with minimal changes. Parameters ---------- self input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the rounded result for each element in ``self``. The returned array must have the same data type as ``self``. Examples -------- >>> x = ivy.Container(a=ivy.array([2.5, 0.5, -1.4]), ... b=ivy.array([5.4, -3.2, 5.2])) >>> y = x.floor() >>> print(y) { a: ivy.array([2., 0., -2.]), b: ivy.array([5., -4., 5.]) } """ return self.static_floor( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_floor_divide( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.floor_divide. This method simply wraps the function, and so the docstring for ivy.floor_divide also applies to this method with minimal changes. Parameters ---------- x1 dividend input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([4., 5., 6.]), b=ivy.array([7., 8., 9.])) >>> x2 = ivy.Container(a=ivy.array([5., 4., 2.5]), b=ivy.array([2.3, 3.7, 5])) >>> y = ivy.Container.static_floor_divide(x1, x2) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 2., 1.]) } With mixed :class:`ivy.Container` and :class:`ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([4., 5., 6.]), b=ivy.array([7., 8., 9.])) >>> x2 = ivy.array([2, 3, 4]) >>> y = ivy.Container.static_floor_divide(x1, x2) >>> print(y) { a: ivy.array([2., 1., 1.]), b: ivy.array([3., 2., 2.]) } """ return ContainerBase.cont_multi_map_in_function( "floor_divide", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def floor_divide( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.floor_divide. This method simply wraps the function, and so the docstring for ivy.floor_divide also applies to this method with minimal changes. Parameters ---------- self dividend input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([4., 5., 6.]), b=ivy.array([7., 8., 9.])) >>> x2 = ivy.Container(a=ivy.array([5., 4., 2.5]), b=ivy.array([2.3, 3.7, 5])) >>> y = x1.floor_divide(x2) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 2., 1.]) } With mixed :class:`ivy.Container` and :class:`ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([4., 5., 6.]), b=ivy.array([7., 8., 9.])) >>> x2 = ivy.array([2, 3, 4]) >>> y = x1.floor_divide(x2) >>> print(y) { a: ivy.array([2., 1., 1.]), b: ivy.array([3., 2., 2.]) } """ return self.static_floor_divide( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_greater( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.greater. This method simply wraps the function, and so the docstring for ivy.greater also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned array must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_greater(y,x) >>> print(z) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) } """ return ContainerBase.cont_multi_map_in_function( "greater", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def greater( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.greater. This method simply wraps the function, and so the docstring for ivy.greater also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned array must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([5, 6, 7])) >>> z = x.greater(y) >>> print(z) { a: ivy.array([True, True, True]), b: ivy.array([False, False, False]) } """ return self.static_greater( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_greater_equal( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.greater_equal. This method simply wraps the function, and so the docstring for ivy.greater_equal also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_greater_equal(y) >>> print(z) { a:ivy.array([True,True,True]), b:ivy.array([False,False,False]) } """ return ContainerBase.cont_multi_map_in_function( "greater_equal", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def greater_equal( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.greater_equal. This method simply wraps the function, and so the docstring for ivy.greater_equal also applies to this metho with minimal changes. Parameters ---------- self input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([5, 6, 7])) >>> z = x.greater_equal(y) >>> print(z) { a:ivy.array([True,True,True]), b:ivy.array([False,False,False]) } """ return self.static_greater_equal( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_isfinite( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.isfinite. This method simply wraps the function, and so the docstring for ivy.isfinite also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``x_i`` is finite and ``False`` otherwise. The returned array must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 999999999999]), ... b=ivy.array([float('-0'), ivy.nan])) >>> y = ivy.Container.static_isfinite(x) >>> print(y) { a: ivy.array([True, True]), b: ivy.array([True, False]) } """ return ContainerBase.cont_multi_map_in_function( "isfinite", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def isfinite( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.isfinite. This method simply wraps the function, and so the docstring for ivy.isfinite also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``self_i`` is finite and ``False`` otherwise. The returned array must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 999999999999]), ... b=ivy.array([float('-0'), ivy.nan])) >>> y = x.isfinite() >>> print(y) { a: ivy.array([True, True]), b: ivy.array([True, False]) } """ return self.static_isfinite( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_isinf( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, detect_positive: bool = True, detect_negative: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.isinf. This method simply wraps the function, and so the docstring for ivy.isinf also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued data type. detect_positive if ``True``, positive infinity is detected. detect_negative if ``True``, negative infinity is detected. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``x_i`` is either positive or negative infinity and ``False`` otherwise. The returned array must have a data type of ``bool``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, -float('inf'), 1.23]), ... b=ivy.array([float('inf'), 3.3, -4.2])) >>> z = ivy.Container.static_isinf(x) >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) } """ return ContainerBase.cont_multi_map_in_function( "isinf", x, detect_positive=detect_positive, detect_negative=detect_negative, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def isinf( self: ivy.Container, *, detect_positive: bool = True, detect_negative: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.isinf. This method simply wraps the function, and so the docstring for ivy.isinf also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued data type. detect_positive if ``True``, positive infinity is detected. detect_negative if ``True``, negative infinity is detected. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``self_i`` is either positive or negative infinity and ``False`` otherwise. The returned array must have a data type of ``bool``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, -float('inf'), 1.23]), ... b=ivy.array([float('inf'), 3.3, -4.2])) >>> z = x.isinf() >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) } """ return self.static_isinf( self, detect_positive=detect_positive, detect_negative=detect_negative, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_isnan( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.isnan. This method simply wraps the function, and so the docstring for ivy.isnan also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``x_i`` is ``NaN`` and ``False`` otherwise. The returned array should have a data type of ``bool``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, -float('nan'), 1.23]), ... b=ivy.array([float('nan'), 3.3, -4.2])) >>> z = ivy.Container.static_isnan(x) >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) } """ return ContainerBase.cont_multi_map_in_function( "isnan", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def isnan( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.isnan. This method simply wraps the function, and so the docstring for ivy.isnan also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``self_i`` is ``NaN`` and ``False`` otherwise. The returned array should have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([-1, -float('nan'), 1.23]), ... b=ivy.array([float('nan'), 3.3, -4.2])) >>> y = x.isnan() >>> print(y) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) } """ return self.static_isnan( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_less( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.less. This method simply wraps the function, and so the docstring for ivy.less also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([5, 6, 7])) >>> z = ivy.Container.static_less(y,x) >>> print(z) { a: ivy.array([True, True, True]), b: ivy.array([False, False, False]) } """ return ContainerBase.cont_multi_map_in_function( "less", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def less( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.less. This method simply wraps the function, and so the docstring for ivy.less also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([4, 5, 6]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([5, 6, 7])) >>> z = x.less(y) >>> print(z) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) } """ return self.static_less( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_less_equal( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.less_equal. This method simply wraps the function, and so the docstring for ivy.less_equal also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- With :code:'ivy.Container' inputs: >>> x1 = ivy.Container(a=ivy.array([12, 3.5, 9.2]), b=ivy.array([2., 1.1, 5.5])) >>> x2 = ivy.Container(a=ivy.array([12, 2.2, 4.1]), b=ivy.array([1, 0.7, 3.8])) >>> y = ivy.Container.static_less_equal(x1, x2) >>> print(y) { a: ivy.array([True, False, False]), b: ivy.array([False, False, False]) } """ return ContainerBase.cont_multi_map_in_function( "less_equal", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def less_equal( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.less_equal. This method simply wraps the function, and so the docstring for ivy.less_equal also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- With :code:'ivy.Container' inputs: >>> x1 = ivy.Container(a=ivy.array([12, 3.5, 9.2]), b=ivy.array([2., 1.1, 5.5])) >>> x2 = ivy.Container(a=ivy.array([12, 2.2, 4.1]), b=ivy.array([1, 0.7, 3.8])) >>> y = x1.less_equal(x2) >>> print(y) { a: ivy.array([True, False, False]), b: ivy.array([False, False, False]) } With mixed :code:'ivy.Container' and :code:'ivy.Array' inputs: >>> x1 = ivy.Container(a=ivy.array([12., 3.5, 9.2]), b=ivy.array([2., 1., 5.5])) >>> x2 = ivy.array([2., 1.1, 5.5]) >>> y = x1.less_equal(x2) >>> print(y) { a: ivy.array([False, False, False]), b: ivy.array([True, True, True]) } """ return self.static_less_equal( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_log( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.log. This method simply wraps the function, and so the docstring for ivy.log also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the log for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- Using :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0.0, float('nan')]), ... b=ivy.array([-0., -3.9, float('+inf')]), ... c=ivy.array([7.9, 1.1, 1.])) >>> y = ivy.Container.static_log(x) >>> print(y) { a: ivy.array([-inf, nan]), b: ivy.array([-inf, nan, inf]), c: ivy.array([2.07, 0.0953, 0.]) } """ return ContainerBase.cont_multi_map_in_function( "log", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def log( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.log. This method simply wraps the function, and so the docstring for ivy.log also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the log for each element in ``self``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([0.0, float('nan')]), ... b=ivy.array([-0., -3.9, float('+inf')]), ... c=ivy.array([7.9, 1.1, 1.])) >>> y = x.log() >>> print(y) { a: ivy.array([-inf, nan]), b: ivy.array([-inf, nan, inf]), c: ivy.array([2.07, 0.0953, 0.]) } """ return self.static_log( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_log1p( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.log1p. This method simply wraps the function, and so the docstring for ivy.log1p also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.1])) >>> y = ivy.Container.static_log1p(x) >>> print(y) { a: ivy.array([0., 0.693, 1.1]), b: ivy.array([1.39, 1.61, 1.81]) } >>> x = ivy.Container(a=ivy.array([0., 2.]), b=ivy.array([ 4., 5.1])) >>> ivy.Container.static_log1p(x, out = x) >>> print(y) { a: ivy.array([0., 0.693, 1.1]), b: ivy.array([1.39, 1.61, 1.81]) } """ return ContainerBase.cont_multi_map_in_function( "log1p", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def log1p( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.log1p. This method simply wraps the function, and so the docstring for ivy.log1p also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``self``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1.6, 2.6, 3.5]), ... b=ivy.array([4.5, 5.3, 2.3])) >>> y = x.log1p() >>> print(y) { a: ivy.array([0.956, 1.28, 1.5]), b: ivy.array([1.7, 1.84, 1.19]) } """ return self.static_log1p( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_log2( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.log2. This method simply wraps the function, and so the docstring for ivy.log2 also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated base ``2`` logarithm for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. """ return ContainerBase.cont_multi_map_in_function( "log2", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def log2( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.log2. This method simply wraps the function, and so the docstring for ivy.log2 also applies to this metho with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated base ``2`` logarithm for each element in ``self``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. """ return self.static_log2( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_log10( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.log10. This method simply wraps the function, and so the docstring for ivy.log10 also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated base ``10`` logarithm for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- Using :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0.0, float('nan')]), ... b=ivy.array([-0., -3.9, float('+inf')]), ... c=ivy.array([7.9, 1.1, 1.])) >>> y = ivy.Container.static_log10(x) >>> print(y) { a: ivy.array([-inf, nan]), b: ivy.array([-inf, nan, inf]), c: ivy.array([0.898, 0.0414, 0.]) } """ return ContainerBase.cont_multi_map_in_function( "log10", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def log10( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.log10. This method simply wraps the function, and so the docstring for ivy.log10 also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated base ``10`` logarithm for each element in ``self``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([0.0, float('nan')]), ... b=ivy.array([-0., -3.9, float('+inf')]), ... c=ivy.array([7.9, 1.1, 1.])) >>> y = x.log10() >>> print(y) { a: ivy.array([-inf, nan]), b: ivy.array([-inf, nan, inf]), c: ivy.array([0.898, 0.0414, 0.]) } """ return self.static_log10( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_logaddexp( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.greater_equal. This method simply wraps the function, and so the docstring for ivy.greater_equal also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- Using :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([4., 5., .]), ... b=ivy.array([2., 3., 4.])) >>> y = ivy.Container(a=ivy.array([1., 2., 3.]), ... b=ivy.array([5., 6., 7.])) >>> z = ivy.Container.static_logaddexp(y,x) >>> print(z) { a: ivy.array([4.05, 5.05, 6.05]), b: ivy.array([5.05, 6.05, 7.05]) } """ return ContainerBase.cont_multi_map_in_function( "logaddexp", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def logaddexp( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.greater_equal. This method simply wraps the function, and so the docstring for ivy.greater_equal also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- Using :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([4., 5., 6.]), ... b=ivy.array([2., 3., 4.])) >>> y = ivy.Container(a=ivy.array([1., 2., 3.]), ... b=ivy.array([5., 6., 7.])) >>> z = ivy.logaddexp(y,x) >>> print(z) { a: ivy.array([4.05, 5.05, 6.05]), b: ivy.array([5.05, 6.05, 7.05]) } """ return self.static_logaddexp( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_logical_and( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.logical_and. This method simply wraps the function, and so the docstring for ivy.logical_and also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a boolean data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- Using 'ivy.Container' instance >>> a = ivy.Container(a=ivy.array([True, False, True, False])) >>> b = ivy.Container(a=ivy.array([True, True, False, False])) >>> w = ivy.Container.static_logical_and(a, b) >>> print(w) { a:ivy.array([True,False,False,False]) } >>> j = ivy.Container(a=ivy.array([True, True, False, False])) >>> m = ivy.array([False, True, False, True]) >>> x = ivy.Container.static_logical_and(j, m) >>> print(x) { a:ivy.array([False,True,False,False]) } >>> k = ivy.Container(a=ivy.array([True, False, True]), ... b=ivy.array([True, False, False])) >>> l = ivy.Container(a=ivy.array([True, True, True]), ... b=ivy.array([False, False, False])) >>> z = ivy.Container.static_logical_and(k, l) >>> print(z) { a:ivy.array([True,False,True]), b:ivy.array([False,False,False]) } """ return ContainerBase.cont_multi_map_in_function( "logical_and", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def logical_and( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.logical_and. This method simply wraps the function, and so the docstring for ivy.logical_and also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a boolean data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- Using 'ivy.Container' instance >>> a = ivy.Container(a=ivy.array([True, False, True, False])) >>> b = ivy.Container(a=ivy.array([True, True, False, False])) >>> w = a.logical_and(b) >>> print(w) { a:ivy.array([True,False,False,False]) } >>> j = ivy.Container(a=ivy.array([True, True, False, False])) >>> m = ivy.array([False, True, False, True]) >>> x = j.logical_and(m) >>> print(x) { a:ivy.array([False,True,False,False]) } >>> k = ivy.Container(a=ivy.array([True, False, True]), ... b=ivy.array([True, False, False])) >>> l = ivy.Container(a=ivy.array([True, True, True]), ... b=ivy.array([False, False, False])) >>> z = k.logical_and(l) >>> print(z) { a:ivy.array([True,False,True]), b:ivy.array([False,False,False]) } """ return self.static_logical_and( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_logical_not( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.logical_not. This method simply wraps the function, and so the docstring for ivy.logical_not also applies to this method with minimal changes. Parameters ---------- x input container. Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``x``. The returned container must have a data type of ``bool``. Examples -------- Using 'ivy.Container' instance >>> x=ivy.Container(a=ivy.array([1,0,0,1]), b=ivy.array([3,1,7,0])) >>> ivy.Container.static_logical_not(x) { a: ivy.array([False, True, True, False]), b: ivy.array([False, False, False, True]) } """ return ContainerBase.cont_multi_map_in_function( "logical_not", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def logical_not( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.logical_not. This method simply wraps the function, and so the docstring for ivy.logical_not also applies to this method with minimal changes. Parameters ---------- self input container. Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``self``. The returned container must have a data type of ``bool``. Examples -------- Using 'ivy.Container' instance >>> x=ivy.Container(a=ivy.array([1,0,0,1]), b=ivy.array([3,1,7,0])) >>> y = x.logical_not() >>> print(y) { a: ivy.array([False, True, True, False]), b: ivy.array([False, False, False, True]) } >>> x=ivy.Container(a=ivy.array([1,0,1,0]), b=ivy.native_array([5,2,0,3])) >>> y = x.logical_not() >>> print(y) { a: ivy.array([False, True, False, True]), b: ivy.array([False, False, True, False]) } """ return self.static_logical_not( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_logical_or( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.logical_or. This method simply wraps the function, and so the docstring for ivy.logical_or also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a boolean data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([False, False, True]), ... b=ivy.array([True, False, True])) >>> y = ivy.Container(a=ivy.array([False, True, False]), ... b=ivy.array([True, True, False])) >>> z = ivy.Container.static_logical_or(x, y) >>> print(z) { a: ivy.array([False, True, True]), b: ivy.array([True, True, True]) } """ return ContainerBase.cont_multi_map_in_function( "logical_or", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def logical_or( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.logical_or. This method simply wraps the function, and so the docstring for ivy.logical_or also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a boolean data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. This function conforms to the `Array API Standard <https://data-apis.org/array-api/latest/>`_. This docstring is an extension of the `docstring <https://data-apis.org/array-api/latest/API_specification/generated/signatures.elementwise_functions.logical_or.html>`_ in the standard. Both the description and the type hints above assumes an array input for simplicity, but this function is *nestable*, and therefore also accepts :class:`ivy.Container` instances in place of any of the arguments. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([False,True,True]), b=ivy.array([3.14, 2.718, 1.618])) >>> y = ivy.Container(a=ivy.array([0, 5.2, 0.8]), b=ivy.array([0.2, 0, 0.9])) >>> z = x.logical_or(y) >>> print(z) { a: ivy.array([False, True, True]), b: ivy.array([True, True, True]) } """ return self.static_logical_or( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_logical_xor( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.logical_xor. This method simply wraps the function, and so the docstring for ivy.logical_xor also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a boolean data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.array([0,0,1,1,0]) >>> y = ivy.Container(a=ivy.array([1,0,0,1,0]), b=ivy.array([1,0,1,0,0])) >>> z = ivy.Container.static_logical_xor(x, y) >>> print(z) { a: ivy.array([True, False, True, False, False]), b: ivy.array([True, False, False, True, False]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1,0,0,1,0]), b=ivy.array([1,0,1,0,0])) >>> y = ivy.Container(a=ivy.array([0,0,1,1,0]), b=ivy.array([1,0,1,1,0])) >>> z = ivy.Container.static_logical_xor(x, y) >>> print(z) { a: ivy.array([True, False, True, False, False]), b: ivy.array([False, False, False, True, False]) } """ return ContainerBase.cont_multi_map_in_function( "logical_xor", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def logical_xor( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.logical_xor. This method simply wraps the function, and so the docstring for ivy.logical_xor also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a boolean data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a boolean data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([1,0,0,1,0]), b=ivy.array([1,0,1,0,0])) >>> y = ivy.Container(a=ivy.array([0,0,1,1,0]), b=ivy.array([1,0,1,1,0])) >>> z = x.logical_xor(y) >>> print(z) { a: ivy.array([True, False, True, False, False]), b: ivy.array([False, False, False, True, False]) } """ return self.static_logical_xor( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_multiply( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.multiply. This method simply wraps the function, and so the docstring for ivy.multiply also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :code:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([15., 4.5, 6.5]),\ b=ivy.array([3.2, 5., 7.5])) >>> x2 = ivy.Container(a=ivy.array([1.7, 2.8, 3.]),\ b=ivy.array([5.6, 1.2, 4.2])) >>> y =ivy.Container.static_multiply(x1, x2) >>> print(y) { a: ivy.array([25.5, 12.6, 19.5]), b: ivy.array([17.9, 6., 31.5]) } """ return ContainerBase.cont_multi_map_in_function( "multiply", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def multiply( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.multiply. This method simply wraps the function, and so the docstring for ivy.multiply also applies to this method with minimal changes. Parameters ---------- self first input array or container. Should have a numeric data type. x2 second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a nuneric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise products. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :code:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([15., 4.5, 6.5]),\ b=ivy.array([3.2, 5., 7.5])) >>> x2 = ivy.Container(a=ivy.array([1.7, 2.8, 3.]),\ b=ivy.array([5.6, 1.2, 4.2])) >>> y = ivy.Container.multiply(x1, x2) >>> print(y) { a: ivy.array([25.5, 12.6, 19.5]), b: ivy.array([17.9, 6., 31.5]) } With mixed :code:`ivy.Container` and :code:`ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([6.2, 4.8, 2.3]),\ b=ivy.array([5., 1.7, 0.1])) >>> x2 = ivy.array([8.3, 3.2, 6.5]) >>> y = ivy.Container.multiply(x1, x2) >>> print(y) { a: ivy.array([51.5, 15.4, 14.9]), b: ivy.array([41.5, 5.44, 0.65]) } """ return self.static_multiply( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_negative( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.negative. This method simply wraps the function, and so the docstring for ivy.negative also applies to this method with minimal changes. Parameters ---------- x input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``x``. The returned container must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., -5.])) >>> y = ivy.Container.static_negative(x) >>> print(y) { a: ivy.array([-0., -1., -2.]), b: ivy.array([-3., -4., 5.]) } """ return ContainerBase.cont_multi_map_in_function( "negative", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def negative( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.negative. This method simply wraps the function, and so the docstring for ivy.negative also applies to this method with minimal changes. Parameters ---------- self input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``self``. The returned container must have the same data type as ``self``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., -5.])) >>> y = x.negative() >>> print(y) { a: ivy.array([-0., -1., -2.]), b: ivy.array([-3., -4., 5.]) } """ return self.static_negative( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_not_equal( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.not_equal. This method simply wraps the function, and so the docstring for ivy.not_equal also applies to this method with minimal changes. Parameters ---------- x1 input array or container. May have any data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). May have any data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12, 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.Container(a=ivy.array([12, 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = ivy.Container.static_not_equal(x1, x2) >>> print(y) { a: ivy.array([False, True, True]), b: ivy.array([True, True, True]) } """ return ContainerBase.cont_multi_map_in_function( "not_equal", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def not_equal( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.not_equal. This method simply wraps the function, and so the docstring for ivy.not_equal also applies to this method with minimal changes. Parameters ---------- self input array or container. May have any data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). May have any data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type of ``bool``. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12, 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.Container(a=ivy.array([12, 2.3, 3]), b=ivy.array([2.4, 3., 2.])) >>> y = x1.not_equal(x2) >>> print(y) { a: ivy.array([False, True, True]), b: ivy.array([True, True, True]) } With mixed :class:`ivy.Container` and :class:`ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 0.9])) >>> x2 = ivy.array([3., 1., 0.9]) >>> y = x1.not_equal(x2) >>> print(y) { a: ivy.array([True, True, True]), b: ivy.array([False, False, False]) } """ return self.static_not_equal( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_positive( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.positive. This method simply wraps the function, and so the docstring for ivy.positive also applies to this method with minimal changes. Parameters ---------- x input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``x``. The returned container must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., -5.])) >>> y = ivy.Container.static_positive(x) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., -5.]) } """ return ContainerBase.cont_multi_map_in_function( "positive", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def positive( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.positive. This method simply wraps the function, and so the docstring for ivy.positive also applies to this method with minimal changes. Parameters ---------- self input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``self``. The returned container must have the same data type as ``self``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., -5.])) >>> y = ivy.positive(x) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., -5.]) } """ return self.static_positive( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_pow( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.pow. This method simply wraps the function, and so the docstring for ivy.pow also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = ivy.Container.static_pow(x, 2) >>> print(y) { a: ivy.array([0, 1]), b: ivy.array([4, 9]) } """ return ContainerBase.cont_multi_map_in_function( "pow", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def pow( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.pow. This method simply wraps the function, and so the docstring for ivy.pow also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = x.pow(3) >>> print(y) { a:ivy.array([0,1]), b:ivy.array([8,27]) } """ return self.static_pow( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_remainder( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, modulus: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.remainder. This method simply wraps the function, and so the docstring for ivy.remainder also applies to this method with minimal changes. Parameters ---------- x1 input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. modulus whether to compute the modulus instead of the remainder. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have the same sign as the respective element ``x2_i``. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([2., 3., 5.]), b=ivy.array([2., 2., 4.])) >>> x2 = ivy.Container(a=ivy.array([1., 3., 4.]), b=ivy.array([1., 3., 3.])) >>> y = ivy.Container.static_remainder(x1, x2) >>> print(y) { a: ivy.array([0., 0., 1.]), b: ivy.array([0., 2., 1.]) } With mixed :class:`ivy.Container` and `ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([2., 3., 5.]), b=ivy.array([2., 2., 4.])) >>> x2 = ivy.array([1., 2., 3.]) >>> y = ivy.Container.static_remainder(x1, x2) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([0., 0., 1.]) } With mixed :class:`ivy.Container` and `ivy.NativeArray` inputs: >>> x1 = ivy.Container(a=ivy.array([2., 3., 5.]), b=ivy.array([2., 2., 4.])) >>> x2 = ivy.native_array([1., 2., 3.]) >>> y = ivy.Container.static_remainder(x1, x2) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([0., 0., 1.]) } """ return ContainerBase.cont_multi_map_in_function( "remainder", x1, x2, modulus=modulus, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def remainder( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, modulus: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.remainder. This method simply wraps the function, and so the docstring for ivy.remainder also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a real-valued data type. x2 input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. modulus whether to compute the modulus instead of the remainder. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have the same sign as the respective element ``x2_i``. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([2., 3., 5.]), b=ivy.array([2., 2., 4.])) >>> x2 = ivy.Container(a=ivy.array([1., 3., 4.]), b=ivy.array([1., 3., 3.])) >>> y = x1.remainder(x2) >>> print(y) { a: ivy.array([0., 0., 1.]), b: ivy.array([0., 2., 1.]) } With mixed :class:`ivy.Container` and `ivy.Array` inputs: >>> x1 = ivy.Container(a=ivy.array([2., 3., 5.]), b=ivy.array([2., 2., 4.])) >>> x2 = ivy.array([1., 2., 3.]) >>> y = x1.remainder(x2) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([0., 0., 1.]) } With mixed :class:`ivy.Container` and `ivy.NativeArray` inputs: >>> x1 = ivy.Container(a=ivy.array([2., 3., 5.]), b=ivy.array([2., 2., 4.])) >>> x2 = ivy.native_array([1., 2., 3.]) >>> y = x1.remainder(x2) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([0., 0., 1.]) } """ return self.static_remainder( self, x2, modulus=modulus, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_round( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.round. This method simply wraps thevfunction, and so the docstring for ivy.round also applies to this method with minimal changes. Parameters ---------- x input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the rounded result for each element in ``x``. The returned container must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([4.20, 8.6, 6.90, 0.0]), ... b=ivy.array([-300.9, -527.3, 4.5])) >>> y = ivy.Container.static_round(x) >>> print(y) { a: ivy.array([4., 9., 7., 0.]), b: ivy.array([-301., -527., 4.]) } """ return ContainerBase.cont_multi_map_in_function( "round", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def round( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.round. This method simply wraps the function, and so the docstring for ivy.round also applies to this method with minimal changes. Parameters ---------- self input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the rounded result for each element in ``self``. The returned container must have the same data type as ``self``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([4.20, 8.6, 6.90, 0.0]), ... b=ivy.array([-300.9, -527.3, 4.5])) >>> y = x.round() >>> print(y) { a: ivy.array([4., 9., 7., 0.]), b: ivy.array([-301., -527., 4.]) } """ return self.static_round( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sign( x: Union[float, ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sign. This method simply wraps the function, and so the docstring for ivy.sign also applies to this method with minimal changes. Parameters ---------- x input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``x``. The returned container must have the same data type as ``x``. Examples -------- >>> x = ivy.Container(a=ivy.array([0, -1., 6.6]), ... b=ivy.array([-14.2, 8.3, 0.1, -0])) >>> y = ivy.Container.static_sign(x) >>> print(y) { a: ivy.array([0., -1., 1.]), b: ivy.array([-1., 1., 1., 0.]) } """ return ContainerBase.cont_multi_map_in_function( "sign", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sign( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sign. This method simply wraps the function, and so the docstring for ivy.sign also applies to this method with minimal changes. Parameters ---------- self input container. Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the evaluated result for each element in ``self``. The returned container must have the same data type as ``self``. Examples -------- >>> x = ivy.Container(a=ivy.array([-6.7, 2.4, -8.5]), ... b=ivy.array([1.5, -0.3, 0]), ... c=ivy.array([-4.7, -5.4, 7.5])) >>> y = x.sign() >>> print(y) { a: ivy.array([-1., 1., -1.]), b: ivy.array([1., -1., 0.]), c: ivy.array([-1., -1., 1.]) } """ return self.static_sign( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sin( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sin. This method simply wraps the function, and so the docstring for ivy.sin also applies to this method with minimal changes. Parameters ---------- x input container whose elements are each expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the sine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([-1., -2., -3.]), ... b=ivy.array([4., 5., 6.])) >>> y = ivy.Container.static_sin(x) >>> print(y) { a: ivy.array([-0.841, -0.909, -0.141]), b: ivy.array([-0.757, -0.959, -0.279]) } """ return ContainerBase.cont_multi_map_in_function( "sin", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sin( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sin. This method simply wraps the function, and so the docstring for ivy.sin also applies to this method with minimal changes. Parameters ---------- self input container whose elements are each expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the sine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1., 2., 3.]), ... b=ivy.array([-4., -5., -6.])) >>> y = x.sin() >>> print(y) { a: ivy.array([0.841, 0.909, 0.141]), b: ivy.array([0.757, 0.959, 0.279]) } """ return self.static_sin( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sinh( x, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sinh. This method simply wraps the function, and so the docstring for ivy.sinh also applies to this method with minimal changes. Parameters ---------- x input container whose elements each represent a hyperbolic angle. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container containing the hyperbolic sine of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([-1, 0.23, 1.12]), b=ivy.array([1, -2, 0.76])) >>> y = ivy.Container.static_sinh(x) >>> print(y) { a: ivy.array([-1.18, 0.232, 1.37]), b: ivy.array([1.18, -3.63, 0.835]) } >>> x = ivy.Container(a=ivy.array([-3, 0.34, 2.]), ... b=ivy.array([0.67, -0.98, -3])) >>> y = ivy.Container(a=ivy.zeros(1), b=ivy.zeros(1)) >>> ivy.Container.static_sinh(x, out=y) >>> print(y) { a: ivy.array([-10., 0.347, 3.63]), b: ivy.array([0.721, -1.14, -10.]) } """ return ContainerBase.cont_multi_map_in_function( "sinh", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sinh( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sinh. This method simply wraps the function, and so the docstring for ivy.sinh also applies to this method with minimal changes. Parameters ---------- self input container whose elements each represent a hyperbolic angle. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an container containing the hyperbolic sine of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([-1, 0.23, 1.12]), b=ivy.array([1, -2, 0.76])) >>> y = x.sinh() >>> print(y) { a: ivy.array([-1.18, 0.232, 1.37]), b: ivy.array([1.18, -3.63, 0.835]) } >>> x = ivy.Container(a=ivy.array([-3, 0.34, 2.]), ... b=ivy.array([0.67, -0.98, -3])) >>> y = ivy.Container(a=ivy.zeros(3), b=ivy.zeros(3)) >>> x.sinh(out=y) >>> print(y) { a: ivy.array([-10., 0.347, 3.63]), b: ivy.array([0.721, -1.14, -10.]) } """ return self.static_sinh( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_square( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.square. This method simply wraps the function, and so the docstring for ivy.square also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the square of each element in ``x``. The returned container must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = ivy.Container.static_square(x) >>> print(y) { a:ivy.array([0,1]), b:ivy.array([4,9]) } """ return ContainerBase.cont_multi_map_in_function( "square", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def square( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.square. This method simply wraps the function, and so the docstring for ivy.square also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the square of each element in ``self``. The returned container must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 1]), b=ivy.array([2, 3])) >>> y = x.square() >>> print(y) { a:ivy.array([0,1]), b:ivy.array([4,9]) } """ return self.static_square( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sqrt( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sqrt. This method simply wraps the function, and so the docstring for ivy.sqrt also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the square root of each element in ``x``. The returned container must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- with :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 100., 27.]), ... b=ivy.native_array([93., 54., 25.])) >>> y = ivy.Container.static_sqrt(x) >>> print(y) { a: ivy.array([0., 10., 5.2]), b: ivy.array([9.64, 7.35, 5.]) } """ return ContainerBase.cont_multi_map_in_function( "sqrt", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sqrt( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sqrt. This method simply wraps the function, and so the docstring for ivy.sqrt also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the square root of each element in ``self``. The returned container must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- with :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 100., 27.]), ... b=ivy.native_array([93., 54., 25.])) >>> y = x.sqrt() >>> print(y) { a: ivy.array([0., 10., 5.2]), b: ivy.array([9.64, 7.35, 5.]) } """ return self.static_sqrt( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_subtract( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, alpha: Optional[Union[int, float]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.subtract. This method simply wraps the function, and so the docstring for ivy.subtract also applies to this method with minimal changes. Parameters ---------- x1 first input array or container. Should have a numeric data type. x2 second input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. alpha optional scalar multiplier for ``x2``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise sums. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 1, 3]), ... b=ivy.array([1, -1, 0])) >>> z = ivy.Container.static_subtract(x, y) >>> print(z) { a: ivy.array([-3, 1, 0]), b: ivy.array([1, 4, 4]) } >>> z = ivy.Container.static_subtract(x, y, alpha=3) >>> print(z) { a: ivy.array([-11, -1, -6]), b: ivy.array([-1, 6, 4]) } """ return ContainerBase.cont_multi_map_in_function( "subtract", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, alpha=alpha, out=out, )
[docs]def subtract( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, alpha: Optional[Union[int, float]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.subtract. This method simply wraps the function, and so the docstring for ivy.subtract also applies to this method with minimal changes. Parameters ---------- self first input array or container. Should have a numeric data type. x2 second input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. alpha optional scalar multiplier for ``x2``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise sums. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 3]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container(a=ivy.array([4, 1, 3]), ... b=ivy.array([1, -1, 0])) >>> z = x.subtract(y) >>> print(z) { a: ivy.array([-3, 1, 0]), b: ivy.array([1, 4, 4]) } >>> z = x.subtract(y, alpha=3) >>> print(z) { a: ivy.array([-11, -1, -6]), b: ivy.array([-1, 6, 4]) } """ return self.static_subtract( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, alpha=alpha, out=out, )
[docs]def static_tan( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.tan. This method simply wraps the function, and so the docstring for ivy.tan also applies to this method with minimal changes. Parameters ---------- x input array whose elements are expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array containing the tangent of each element in ``x``. The return must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_tan(x) >>> print(y) { a: ivy.array([0., 1.56, -2.19]), b: ivy.array([-0.143, 1.16, -3.38]) } """ return ContainerBase.cont_multi_map_in_function( "tan", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def tan( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.tan. This method simply wraps the function, and so the docstring for ivy.tan also applies to this method with minimal changes. Parameters ---------- self input array whose elements are expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the tangent of each element in ``self``. The return must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.tan() >>> print(y) { a:ivy.array([0., 1.56, -2.19]), b:ivy.array([-0.143, 1.16, -3.38]) } """ return self.static_tan( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_tanh( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.tanh. This method simply wraps the function, and so the docstring for ivy.tanh also applies to this method with minimal changes. Parameters ---------- x input container whose elements each represent a hyperbolic angle. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the hyperbolic tangent of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_tanh(x) >>> print(y) { a: ivy.array([0., 0.76, 0.96]), b: ivy.array([0.995, 0.999, 0.9999]) } """ return ContainerBase.cont_multi_map_in_function( "tanh", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def tanh( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.tanh. This method simply wraps the function, and so the docstring for ivy.tanh also applies to this method with minimal changes. Parameters ---------- self input container whose elements each represent a hyperbolic angle. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the hyperbolic tangent of each element in ``self``. The returned container must have a real-valued floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> y = x.tanh() >>> print(y) { a:ivy.array([0., 0.762, 0.964]), b:ivy.array([0.995, 0.999, 1.]) } """ return self.static_tanh( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_trunc( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.trunc. This method simply wraps the function, and so the docstring for ivy.trunc also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the rounded result for each element in ``x``. The returned container must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-0.25, 4, 1.3]), ... b=ivy.array([12, -3.5, 1.234])) >>> y = ivy.Container.static_trunc(x) >>> print(y) { a: ivy.array([-0., 4., 1.]), b: ivy.array([12., -3., 1.]) } """ return ContainerBase.cont_multi_map_in_function( "trunc", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def trunc( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.trunc. This method simply wraps the function, and so the docstring for ivy.trunc also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the rounded result for each element in ``self``. The returned container must have the same data type as ``self``. Examples -------- >>> x = ivy.Container(a=ivy.array([-0.25, 4, 1.3]), ... b=ivy.array([12, -3.5, 1.234])) >>> y = x.trunc() >>> print(y) { a: ivy.array([-0., 4., 1.]), b: ivy.array([12., -3., 1.]) } """ return self.static_trunc( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_erf( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.erf. This method simply wraps the function, and so the docstring for ivy.erf also applies to this method with minimal changes. Parameters ---------- x input container to compute exponential for. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the Gauss error of ``x``. Examples -------- >>> x = ivy.Container(a=ivy.array([-0.25, 4, 1.3]), ... b=ivy.array([12, -3.5, 1.234])) >>> y = ivy.Container.static_erf(x) >>> print(y) { a: ivy.array([-0.27632612, 1., 0.934008]), b: ivy.array([1., -0.99999928, 0.91903949]) } """ return ContainerBase.cont_multi_map_in_function( "erf", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def erf( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.erf. This method simply wraps thefunction, and so the docstring for ivy.erf also applies to this method with minimal changes. Parameters ---------- self input container to compute exponential for. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the Gauss error of ``self``. Examples -------- >>> x = ivy.Container(a=ivy.array([-0.25, 4, 1.3]), ... b=ivy.array([12, -3.5, 1.234])) >>> y = x.erf() >>> print(y) { a: ivy.array([-0.27632612, 1., 0.934008]), b: ivy.array([1., -0.99999928, 0.91903949]) } """ return self.static_erf( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_minimum( x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, use_where: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.minimum. This method simply wraps the function, and so the docstring for ivy.minimum also applies to this method with minimal changes. Parameters ---------- x1 Input array containing elements to minimum threshold. x2 The other container or number to compute the minimum against. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. use_where Whether to use :func:`where` to calculate the minimum. If ``False``, the minimum is calculated using the ``(x + y - |x - y|)/2`` formula. Default is ``True``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- Container object with all sub-arrays having the minimum values computed. Examples -------- With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 3, 1]), ... b=ivy.array([2, 8, 5])) >>> y = ivy.Container(a=ivy.array([1, 5, 6]), ... b=ivy.array([5, 9, 7])) >>> z = ivy.Container.static_minimum(x, y) >>> print(z) { a: ivy.array([1, 3, 1]), b: ivy.array([2, 8, 5]) } """ return ContainerBase.cont_multi_map_in_function( "minimum", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, use_where=use_where, out=out, )
[docs]def minimum( self: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, use_where: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.minimum. This method simply wraps the function, and so the docstring for ivy.minimum also applies to this method with minimal changes. Parameters ---------- self Input array containing elements to minimum threshold. x2 The other container or number to compute the minimum against. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. use_where Whether to use :func:`where` to calculate the minimum. If ``False``, the minimum is calculated using the ``(x + y - |x - y|)/2`` formula. Default is ``True``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- Container object with all sub-arrays having the minimum values computed. Examples -------- With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 3, 1]), ... b=ivy.array([2, 8, 5])) >>> y = ivy.Container(a=ivy.array([1, 5, 6]), ... b=ivy.array([5, 9, 7])) >>> z = x.minimum(y) >>> print(z) { a: ivy.array([1, 3, 1]), b: ivy.array([2, 8, 5]) } """ return self.static_minimum( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, use_where=use_where, out=out, )
[docs]def static_maximum( x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, use_where: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.maximum. This method simply wraps the function, and so the docstring for ivy.maximum also applies to this method with minimal changes. Parameters ---------- x1 Input array containing elements to maximum threshold. x2 Tensor containing maximum values, must be broadcastable to x1. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. use_where Whether to use :func:`where` to calculate the maximum. If ``False``, the maximum is calculated using the ``(x + y + |x - y|)/2`` formula. Default is ``True``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the elements of x1, but clipped to not be lower than the x2 values. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.array([[1, 3], [2, 4], [3, 7]]) >>> y = ivy.Container(a=ivy.array([1, 0,]), ... b=ivy.array([-5, 9])) >>> z = ivy.Container.static_maximum(x, y) >>> print(z) { a: ivy.array([[1, 3], [2, 4], [3, 7]]), b: ivy.array([[1, 9], [2, 9], [3, 9]]) } """ return ContainerBase.cont_multi_map_in_function( "maximum", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, use_where=use_where, out=out, )
[docs]def maximum( self: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, use_where: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.maximum. This method simply wraps the function, and so the docstring for ivy.maximum also applies to this method with minimal changes. Parameters ---------- self Input array containing elements to maximum threshold. x2 Tensor containing maximum values, must be broadcastable to x1. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. use_where Whether to use :func:`where` to calculate the maximum. If ``False``, the maximum is calculated using the ``(x + y + |x - y|)/2`` formula. Default is ``True``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret An container with the elements of x1, but clipped to not be lower than the x2 values. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.array([[1, 3], [2, 4], [3, 7]]) >>> y = ivy.Container(a=ivy.array([1, 0,]), ... b=ivy.array([-5, 9])) >>> z = x.maximum(y) >>> print(z) { a: ivy.array([[1, 3], [2, 4], [3, 7]]), b: ivy.array([[1, 9], [2, 9], [3, 9]]) } """ return self.static_maximum( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, use_where=use_where, out=out, )
[docs]def static_reciprocal( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.reciprocal. This method simply wraps the function, and so the docstring for ivy.reciprocal also applies to this method with minimal changes. Parameters ---------- x input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the element-wise recirpocal of ``x`` Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([4, 5])) >>> y = ivy.Container.static_reciprocal(x) >>> print(y) { a: ivy.array([1, 0.5]), b: ivy.array([0.25, 0.2]) } """ return ContainerBase.cont_multi_map_in_function( "reciprocal", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def reciprocal( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.reciprocal. This method simply wraps the function, and so the docstring for ivy.reciprocal also applies to this method with minimal changes. Parameters ---------- self input container to compute the element-wise reciprocal for. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with the element-wise recirpocal of ``x`` Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([4, 5])) >>> y = x.reciprocal() >>> print(y) { a: ivy.array([1, 0.5]), b: ivy.array([0.25, 0.2]) } """ return self.static_reciprocal( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_deg2rad( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.deg2rad. This method simply wraps the function, and so the docstring for ivy.deg2rad also applies to this method with minimal changes. Parameters ---------- x input container. to be converted from degrees to radians. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with each element in ``x`` converted from degrees to radians. Examples -------- >>> x=ivy.Container(a=ivy.array([0,90,180,270,360]), ... b=ivy.native_array([0,-1.5,-50,ivy.nan])) >>> y=ivy.Container.static_deg2rad(x) >>> print(y) { a: ivy.array([0., 1.57, 3.14, 4.71, 6.28]), b: ivy.array([0., -0.0262, -0.873, nan]) } """ return ContainerBase.cont_multi_map_in_function( "deg2rad", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def deg2rad( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.deg2rad. This method simply wraps the function, and so the docstring for ivy.deg2rad also applies to this method with minimal changes. Parameters ---------- self input container. to be converted from degrees to radians. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with each element in ``x`` converted from degrees to radians. Examples -------- With :class:`ivy.Container` input: >>> x=ivy.Container(a=ivy.array([0., 0.351, -0.881, ivy.nan]), ... b=ivy.native_array([0,-1.5,-50,ivy.nan])) >>> y=x.deg2rad() >>> print(y) { a: ivy.array([0., 0.00613, -0.0154, nan]), b: ivy.array([0., -0.0262, -0.873, nan]) } """ return self.static_deg2rad( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_rad2deg( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.rad2deg. This method simply wraps the function, and so the docstring for ivy.rad2deg also applies to this method with minimal changes. Parameters ---------- x input container. to be converted from radians to degrees. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with each element in ``x`` converted from radians to degrees. Examples -------- >>> x=ivy.Container(a=ivy.array([0,90,180,270,360]), ... b=ivy.native_array([0,-1.5,-50,ivy.nan])) >>> y=ivy.Container.static_rad2deg(x) >>> print(y) { a: ivy.array([0., 5160., 10300., 15500., 20600.]), b: ivy.array([0., -85.9, -2860., nan]) } """ return ContainerBase.cont_multi_map_in_function( "rad2deg", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def rad2deg( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.rad2deg. This method simply wraps the function, and so the docstring for ivy.rad2deg also applies to this method with minimal changes. Parameters ---------- self input container. to be converted from radians to degrees. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container with each element in ``x`` converted from radians to degrees. Examples -------- With :class:`ivy.Container` input: >>> x=ivy.Container(a=ivy.array([0., 0.351, -0.881, ivy.nan]), ... b=ivy.native_array([0,-1.5,-50,7.2])) >>> y=x.rad2deg() >>> print(y) { a: ivy.array([0., 20.1, -50.5, nan]), b: ivy.array([0., -85.9, -2860., 413.]) } """ return self.static_rad2deg( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_trunc_divide( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.trunc_divide. This method simply wraps the function, and so the docstring for ivy.trunc_divide also applies to this method with minimal changes. Parameters ---------- x1 dividend input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 9.])) >>> x2 = ivy.Container(a=ivy.array([1., 2.3, -3]), b=ivy.array([2.4, 3., -2.])) >>> y = ivy.Container.static_divide(x1, x2) >>> print(y) { a: ivy.array([12., 1., -2.]), b: ivy.array([1., 0., -4.]) } """ return ContainerBase.cont_multi_map_in_function( "trunc_divide", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def trunc_divide( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.trunc_divide. This method simply wraps the function, and so the docstring for ivy.trunc_divide also applies to this method with minimal changes. Parameters ---------- self dividend input array or container. Should have a real-valued data type. x2 divisor input array or container. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the element-wise results. The returned container must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` inputs: >>> x1 = ivy.Container(a=ivy.array([12., 3.5, 6.3]), b=ivy.array([3., 1., 9.])) >>> x2 = ivy.Container(a=ivy.array([1., 2.3, -3]), b=ivy.array([2.4, 3., -2.])) >>> y = x1.trunc_divide(x2) >>> print(y) { a: ivy.array([12., 1., -2.]), b: ivy.array([1., 0., -4.]) } """ return self.static_trunc_divide( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_isreal( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.isreal. This method simply wraps the function, and so the docstring for ivy.isreal also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``x_i`` is real number and ``False`` otherwise. The returned array should have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([-1+5j, 0-0j, 1.23j]), ... b=ivy.array([7.9, 3.3j, -4.2-5.9j])) >>> z = ivy.Container.static_isreal(x) >>> print(z) { a: ivy.array([False, True, False]), b: ivy.array([True, False, False]) } """ return ContainerBase.cont_multi_map_in_function( "isreal", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def isreal( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.isreal. This method simply wraps the function, and so the docstring for ivy.isreal also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``True`` if ``self_i`` is real number and ``False`` otherwise. The returned array should have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([-1j, -np.inf, 1.23+7j]),\ b=ivy.array([0.0, 3.3j, 1+0j])) >>> y = x.isreal() >>> print(y) { a: ivy.array([False, True, False]), b: ivy.array([True, False, True]) } """ return self.static_isreal( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
def static_trapz( y: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, x: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]], dx: Optional[float] = 1.0, axis: Optional[int] = -1, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.trapz. This method simply wraps the function, and so the docstring for ivy.trapz also applies to this method with minimal changes. Parameters ---------- y The container whose arrays should be integrated. x The sample points corresponding to the input array values. If x is None, the sample points are assumed to be evenly spaced dx apart. The default is None. dx The spacing between sample points when x is None. The default is 1. axis The axis along which to integrate. out optional output container, for writing the result to. Returns ------- ret container including definite integrals of n-dimensional arrays as approximated along a single axis by the trapezoidal rule. Examples -------- With one :class:`ivy.Container` input: >>> y = ivy.Container(a=ivy.array((1, 2, 3)), b=ivy.array((1, 5, 10))) >>> ivy.Container.static_trapz(y) { a: 4.0 b: 10.5 } """ return ContainerBase.cont_multi_map_in_function( "trapz", y, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, x=x, dx=dx, axis=axis, out=out, ) def trapz( self: ivy.Container, /, *, x: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]], dx: Optional[float] = 1.0, axis: Optional[int] = -1, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.trapz. This method simply wraps the function, and so the docstring for ivy.trapz also applies to this method with minimal changes. Parameters ---------- self The container whose arrays should be integrated. x The sample points corresponding to the input array values. If x is None, the sample points are assumed to be evenly spaced dx apart. The default is None. dx The spacing between sample points when x is None. The default is 1. axis The axis along which to integrate. out optional output container, for writing the result to. Returns ------- ret container including definite integrals of n-dimensional arrays as approximated along a single axis by the trapezoidal rule. Examples -------- With one :class:`ivy.Container` input: >>> y = ivy.Container(a=ivy.array((1, 2, 3)), b=ivy.array((1, 5, 10))) >>> y.trapz() { a: 4.0 b: 10.5 } """ return self.static_trapz(self, x=x, dx=dx, axis=axis, out=out) #ivy.container.experimental from ivy.container.base import ContainerBase from typing import Union, List, Dict, Optional import ivy # global from typing import Optional, Tuple, Union, List, Dict # local import ivy from ivy.container.base import ContainerBase from ivy.container.base import ContainerBase from ivy.container.base import ContainerBase # global from typing import ( Optional, Union, List, Dict, Sequence, Tuple, Literal, Any, Callable, Iterable, ) from numbers import Number # local import ivy from ivy.container.base import ContainerBase # global from typing import Union, Optional # local import ivy from ivy.container.base import ContainerBase from ivy.container.base import ContainerBase from typing import Union, Optional, List, Dict import ivy # global from typing import Optional, Union, List, Dict, Tuple, Sequence # local import ivy from ivy.container.base import ContainerBase from ivy.container.base import ContainerBase # global from typing import Optional, Union, List, Dict, Tuple, Literal # local import ivy from ivy.container.base import ContainerBase # global from typing import Union, Optional, List, Dict # local from ivy.container.base import ContainerBase import ivy from ivy.container.base import ContainerBase # global from typing import Optional, Union, List, Dict, Tuple from numbers import Number # local import ivy from ivy.container.base import ContainerBase from ivy.container.base import ContainerBase from ivy.container.base import ContainerBase # global from typing import Optional, Union, List, Dict # local import ivy from ivy.container.base import ContainerBase from typing import Optional import ivy from ivy.container.base import ContainerBase # global from typing import Optional, List, Union, Dict # local from ivy.container.base import ContainerBase import ivy from ivy.container.base import ContainerBase from ivy.container.base import ContainerBase
[docs]def static_l2_normalize( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], axis: int = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out=None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.l2_normalize. This method simply wraps the function, and so the docstring for ivy.l2_normalize also applies to this method with minimal changes. Parameters ---------- x The input container with leaves to be normalized. axis The axis along which to normalize. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the normalized leaves. Examples -------- >>> x = ivy.Container(a=ivy.array([[0.5, 1.5, 2.5], [3.5, 4.5, 5.5]]))) ... b=ivy.array([[-1., -1.], [-1., -0.5]]])) >>> y = ivy.Container.static_l2_normalize(x, axis=1) >>> print(y) { a: ivy.array([[0.16903085, 0.50709254, 0.84515423], [0.44183609, 0.56807494, 0.69431382]]), b: ivy.array([[-0.70710677, -0.70710677], [-0.89442718, -0.44721359]]) } """ return ContainerBase.cont_multi_map_in_function( "l2_normalize", x, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def l2_normalize( self, axis=None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out=None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.l2_normalize. This method simply wraps the function, and so the docstring for ivy.l2_normalize also applies to this method with minimal changes. Parameters ---------- self The input container with leaves to be normalized. axis The axis along which to normalize. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the normalized leaves. Examples -------- >>> x = ivy.Container(a=ivy.array([[0.5, 1.5, 2.5], [3.5, 4.5, 5.5]]))) ... b=ivy.array([[-1., -1.], [-1., -0.5]]])) >>> y = x.static_l2_normalize(axis=1) >>> print(y) { a: ivy.array([[0.16903085, 0.50709254, 0.84515423], [0.44183609, 0.56807494, 0.69431382]]), b: ivy.array([[-0.70710677, -0.70710677], [-0.89442718, -0.44721359]]) } """ return self.static_l2_normalize( self, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_triu_indices( n_rows: int, n_cols: Optional[int] = None, k: Optional[int] = 0, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, out: Optional[Tuple[ivy.Array]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "triu_indices", n_rows, n_cols, k, key_chains, to_apply, prune_unapplied, map_sequences, device=device, out=out, )
[docs]def triu_indices( self: ivy.Container, n_rows: int, n_cols: Optional[int] = None, k: Optional[int] = 0, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, out: Optional[Tuple[ivy.Array]] = None, ) -> ivy.Container: return self.static_triu_indices( self, n_rows, n_cols, k, key_chains, to_apply, prune_unapplied, map_sequences, device=device, out=out, )
[docs]def static_hann_window( window_length: Union[int, ivy.Container], periodic: Optional[bool] = True, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.hann_window. This method simply wraps the function, and so the docstring for ivy.hann_window also applies to this method with minimal changes. Parameters ---------- window_length container including multiple window sizes. periodic If True, returns a window to be used as periodic function. If False, return a symmetric window. dtype The data type to produce. Must be a floating point type. out optional output container, for writing the result to. Returns ------- ret The container that contains the Hann windows. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=3, b=5) >>> ivy.Container.static_hann(x) { a: ivy.array([0.0000, 0.7500, 0.7500]) b: ivy.array([0.0000, 0.3455, 0.9045, 0.9045, 0.3455]) } """ return ContainerBase.cont_multi_map_in_function( "hann_window", window_length, periodic, dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def hann_window( self: ivy.Container, periodic: Optional[bool] = True, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.hann_window. This method simply wraps the function, and so the docstring for ivy.hann_window also applies to this method with minimal changes. Parameters ---------- self input container with window sizes. periodic If True, returns a window to be used as periodic function. If False, return a symmetric window. dtype The data type to produce. Must be a floating point type. out optional output container, for writing the result to. Returns ------- ret The container containing the Hann windows. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=3, b=5) >>> ivy.hann_window(x) { a: ivy.array([0.0000, 0.7500, 0.7500]) b: ivy.array([0.0000, 0.3455, 0.9045, 0.9045, 0.3455]) } """ return self.static_hann_window(self, periodic, dtype, out=out)
[docs]def static_kaiser_window( window_length: Union[int, ivy.Container], periodic: bool = True, beta: float = 12.0, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.kaiser_window. This method simply wraps the function, and so the docstring for ivy.kaiser_window also applies to this method with minimal changes. Parameters ---------- window_length input container including window lenghts. periodic If True, returns a periodic window suitable for use in spectral analysis. If False, returns a symmetric window suitable for use in filter design. beta a float used as shape parameter for the window. dtype data type of the returned array. out optional output container, for writing the result to. Returns ------- ret The container that includes the Kaiser windows. Examples -------- >>> x = ivy.Container(a=3, b=5) >>> ivy.Container.static_kaiser_window(x, True, 5) { a: ivy.array([0.2049, 0.8712, 0.8712]), a: ivy.array([0.0367, 0.7753, 0.7753]), } """ return ContainerBase.cont_multi_map_in_function( "kaiser_window", window_length, periodic, beta, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def kaiser_window( self: ivy.Container, periodic: bool = True, beta: float = 12.0, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.kaiser_window. This method simply wraps the function, and so the docstring for ivy.kaiser_window also applies to this method with minimal changes. Parameters ---------- self input container including window lenghts. periodic If True, returns a periodic window suitable for use in spectral analysis. If False, returns a symmetric window suitable for use in filter design. beta a float used as shape parameter for the window. dtype data type of the returned array. out optional output container, for writing the result to. Returns ------- ret The container that includes the Kaiser windows. Examples -------- >>> x = ivy.Container(a=3, b=5) >>> ivy.Container.static_kaiser_window(x, True, 5) { a: ivy.array([0.2049, 0.8712, 0.8712]), a: ivy.array([0.0367, 0.7753, 0.7753]), } """ return self.static_kaiser_window( self, periodic, beta, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def static_kaiser_bessel_derived_window( x: Union[int, ivy.Array, ivy.NativeArray, ivy.Container], periodic: bool = True, beta: float = 12.0, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.kaiser_bessel_derived_window. This method simply wraps the function, and so the docstring for ivy.kaiser_bessel_derived_window also applies to this method with minimal changes. Parameters ---------- x input container including window lenghts. periodic If True, returns a periodic window suitable for use in spectral analysis. If False, returns a symmetric window suitable for use in filter design. beta a float used as shape parameter for the window. dtype data type of the returned array. out optional output container, for writing the result to. Returns ------- ret The container that includes the Kaiser Bessel Derived windows. Examples -------- >>> x = ivy.Container(a=3, b=5) >>> ivy.Container.static_kaiser_bessel_derived_window(x, True, 5) { a: ivy.array([0.70710677, 0.70710677]), b: ivy.array([0.18493208, 0.9827513 , 0.9827513 , 0.18493208]), } """ return ContainerBase.cont_multi_map_in_function( "kaiser_bessel_derived_window", x, periodic, beta, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def kaiser_bessel_derived_window( self: ivy.Container, periodic: bool = True, beta: float = 12.0, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.kaiser_bessel_derived_window. This method simply wraps the function, and so the docstring for ivy.kaiser_bessel_derived_window also applies to this method with minimal changes. Parameters ---------- self input container including window lenghts. periodic If True, returns a periodic window suitable for use in spectral analysis. If False, returns a symmetric window suitable for use in filter design. beta a float used as shape parameter for the window. dtype data type of the returned array. out optional output container, for writing the result to. Returns ------- ret The container that includes the Kaiser Bessel Derived windows. Examples -------- >>> x = ivy.Container(a=3, b=5)) >>> x.kaiser_bessel_derived_window(True, 5) { a: ivy.array([0.70710677, 0.70710677]), b: ivy.array([0.18493208, 0.9827513 , 0.9827513 , 0.18493208]), } """ return self.static_kaiser_bessel_derived_window( self, periodic, beta, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def static_hamming_window( x: Union[int, ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, periodic: Optional[bool] = True, alpha: Optional[float] = 0.54, beta: Optional[float] = 0.46, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.hamming_window. This method simply wraps the function, and so the docstring for ivy.hamming_window also applies to this method with minimal changes. Parameters ---------- x input container including window lenghts. periodic If True, returns a window to be used as periodic function. If False, return a symmetric window. alpha The coefficient alpha in the hamming window equation beta The coefficient beta in the hamming window equation dtype data type of the returned arrays. out optional output container, for writing the result to. Returns ------- ret The container that includes the Hamming windows. Examples -------- >>> x = ivy.Container(a=3, b=5) >>> ivy.Container.static_hamming_window(x, periodic=True, alpha=0.2, beta=2) { a: ivy.array([-1.8000, 1.2000, 1.2000]), b: ivy.array([-1.8000, -0.4180, 1.8180, 1.8180, -0.4180]) } """ return ContainerBase.cont_multi_map_in_function( "hamming_window", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, periodic=periodic, alpha=alpha, beta=beta, dtype=dtype, out=out, )
[docs]def hamming_window( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, periodic: Optional[bool] = True, alpha: Optional[float] = 0.54, beta: Optional[float] = 0.46, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.hamming_window. This method simply wraps the function, and so the docstring for ivy.hamming_window also applies to this method with minimal changes. Parameters ---------- self input container including window lenghts. periodic If True, returns a window to be used as periodic function. If False, return a symmetric window. alpha The coefficient alpha in the hamming window equation beta The coefficient beta in the hamming window equation dtype data type of the returned arrays. out optional output container, for writing the result to. Returns ------- ret The container that includes the Hamming windows. Examples -------- >>> x = ivy.Container(a=3, b=5)) >>> x.hamming_window(periodic=True, alpha=0.2, beta=2) { a: ivy.array([-1.8000, 1.2000, 1.2000]), b: ivy.array([-1.8000, -0.4180, 1.8180, 1.8180, -0.4180]) } """ return self.static_hamming_window( self, periodic=periodic, alpha=alpha, beta=beta, dtype=dtype, out=out )
[docs]def static_vorbis_window( x: Union[int, ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.vorbis_window. This method simply wraps the function, and so the docstring for ivy.vorbis_window also applies to this method with minimal changes. Parameters ---------- x input container including window lenghts. dtype data type of the returned arrays. out optional output container, for writing the result to. Returns ------- ret The container that includes the vorbis windows. Examples -------- >>> x = ivy.Container(a=3, b=5) >>> ivy.Container.static_vorbis_window(x) { a: ivy.array([0., 0.38268343, 0.92387953, 1., 0.92387953, 0.38268343]), b: ivy.array([0., 0.14943586, 0.51644717, 0.85631905, 0.98877142, 1., 0.98877142, 0.85631905, 0.51644717, 0.14943586]) } """ return ContainerBase.cont_multi_map_in_function( "vorbis_window", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def vorbis_window( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Array, ivy.NativeArray]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.vorbis_window. This method simply wraps the function, and so the docstring for ivy.vorbis_window also applies to this method with minimal changes. Parameters ---------- self input container including window lenghts. dtype data type of the returned arrays. out optional output container, for writing the result to. Returns ------- ret The container that includes the vorbis windows. Examples -------- >>> x = ivy.Container(a=3, b=5)) >>> x.vorbis_window() { a: ivy.array([0., 0.38268343, 0.92387953, 1., 0.92387953, 0.38268343]), b: ivy.array([0., 0.14943586, 0.51644717, 0.85631905, 0.98877142, 1., 0.98877142, 0.85631905, 0.51644717, 0.14943586]) } """ return self.static_vorbis_window( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def static_tril_indices( n_rows: int, n_cols: Optional[int] = None, k: Optional[int] = 0, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return ContainerBase.multi_map_in_static_method( "tril_indices", n_rows, n_cols, k, key_chains, to_apply, prune_unapplied, map_sequences, device=device, )
[docs]def tril_indices( self: ivy.Container, n_rows: int, n_cols: Optional[int] = None, k: Optional[int] = 0, /, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, ) -> ivy.Container: return self.static_tril_indices( self, n_rows, n_cols, k, key_chains, to_apply, prune_unapplied, map_sequences, device=device, )
[docs]def static_moveaxis( a: Union[ivy.Array, ivy.NativeArray, ivy.Container], source: Union[int, Sequence[int]], destination: Union[int, Sequence[int]], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.moveaxis. This method simply wraps the function, and so the docstring for ivy.moveaxis also applies to this method with minimal changes. Parameters ---------- a The container with the arrays whose axes should be reordered. source Original positions of the axes to move. These must be unique. destination Destination positions for each of the original axes. These must also be unique. out optional output container, for writing the result to. Returns ------- ret Container including arrays with moved axes. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.zeros((3, 4, 5)), b=ivy.zeros((2,7,6))) >>> ivy.Container.static_moveaxis(x, 0, -1).shape { a: (4, 5, 3) b: (7, 6, 2) } """ return ContainerBase.cont_multi_map_in_function( "moveaxis", a, source, destination, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def moveaxis( self: ivy.Container, source: Union[int, Sequence[int]], destination: Union[int, Sequence[int]], /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.moveaxis. This method simply wraps the function, and so the docstring for ivy.flatten also applies to this method with minimal changes. Parameters ---------- self The container with the arrays whose axes should be reordered. source Original positions of the axes to move. These must be unique. destination Destination positions for each of the original axes. These must also be unique. out optional output container, for writing the result to. Returns ------- ret Container including arrays with moved axes. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.zeros((3, 4, 5)), b=ivy.zeros((2,7,6))) >>> x.moveaxis(, 0, -1).shape { a: (4, 5, 3) b: (7, 6, 2) } """ return self.static_moveaxis(self, source, destination, out=out)
[docs]def static_heaviside( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.heaviside. This method simply wraps the function, and so the docstring for ivy.heaviside also applies to this method with minimal changes. Parameters ---------- x1 input container including the arrays. x2 values to use where the array is zero. out optional output container array, for writing the result to. Returns ------- ret output container with element-wise Heaviside step function of each array. Examples -------- With :class:`ivy.Array` input: >>> x1 = ivy.Container(a=ivy.array([-1.5, 0, 2.0]), b=ivy.array([3.0, 5.0]) >>> x2 = ivy.Container(a=0.5, b=[1.0, 2.0]) >>> ivy.Container.static_heaviside(x1, x2) { a: ivy.array([ 0. , 0.5, 1. ]) b: ivy.array([1.0, 1.0]) } """ return ContainerBase.cont_multi_map_in_function( "heaviside", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def heaviside( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.heaviside. This method simply wraps the function, and so the docstring for ivy.heaviside also applies to this method with minimal changes. Parameters ---------- self input container including the arrays. x2 values to use where the array is zero. out optional output container array, for writing the result to. Returns ------- ret output container with element-wise Heaviside step function of each array. Examples -------- With :class:`ivy.Array` input: >>> x1 = ivy.Container(a=ivy.array([-1.5, 0, 2.0]), b=ivy.array([3.0, 5.0]) >>> x2 = ivy.Container(a=0.5, b=[1.0, 2.0]) >>> x1.heaviside(x2) { a: ivy.array([ 0. , 0.5, 1. ]) b: ivy.array([1.0, 1.0]) } """ return self.static_heaviside(self, x2, out=out)
[docs]def static_flipud( m: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.flipud. This method simply wraps the function, and so the docstring for ivy.flipud also applies to this method with minimal changes. Parameters ---------- m the container with arrays to be flipped. out optional output container, for writing the result to. Returns ------- ret container including arrays corresponding to the input container's array with elements order reversed along axis 0. Examples -------- With one :class:`ivy.Container` input: >>> m = ivy.Container(a=ivy.diag([1, 2, 3]), b=ivy.arange(4)) >>> ivy.Container.static_flipud(m) { a: ivy.array( [[ 0., 0., 3.], [ 0., 2., 0.], [ 1., 0., 0.]] ) b: ivy.array([3, 2, 1, 0]) } """ return ContainerBase.cont_multi_map_in_function( "flipud", m, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def flipud( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.flipud. This method simply wraps the function, and so the docstring for ivy.flipud also applies to this method with minimal changes. Parameters ---------- self the container with arrays to be flipped. out optional output container, for writing the result to. Returns ------- ret container including arrays corresponding to the input container's array with elements order reversed along axis 0. Examples -------- With one :class:`ivy.Container` input: >>> m = ivy.Container(a=ivy.diag([1, 2, 3]), b=ivy.arange(4)) >>> m.flipud() { a: ivy.array( [[ 0., 0., 3.], [ 0., 2., 0.], [ 1., 0., 0.]] ) b: ivy.array([3, 2, 1, 0]) } """ return self.static_flipud(self, out=out)
[docs]def vstack( self: ivy.Container, /, xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.stack. This method simply wraps the function, and so the docstring for ivy.stack also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]])) >>> x.vstack([y]) { a: ivy.array([[[0, 1], [2, 3]], [[3, 2], [1, 0]]]), b: ivy.array([[[4, 5]], [[1, 0]]]) } """ new_xs = xs.cont_copy() if ivy.is_ivy_container(xs) else xs.copy() new_xs.insert(0, self.cont_copy()) return self.static_vstack( new_xs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_vstack( xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.stack. This method simply wraps the function, and so the docstring for ivy.vstack also applies to this method with minimal changes. Examples -------- With one :class:`ivy.Container` input: >>> c = ivy.Container(a=[ivy.array([1,2,3]), ivy.array([0,0,0])], b=ivy.arange(3)) >>> ivy.Container.static_vstack(c) { a: ivy.array([[1, 2, 3], [0, 0, 0]]), b: ivy.array([[0], [1], [2]]) } """ return ContainerBase.cont_multi_map_in_function( "vstack", xs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def hstack( self: ivy.Container, /, xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.hstack. This method simply wraps the function, and so the docstring for ivy.hstack also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]])) >>> x.hstack([y]) { a: ivy.array([[0, 1, 3, 2], [2, 3, 1, 0]]), b: ivy.array([[4, 5, 1, 0]]) } """ new_xs = xs.cont_copy() if ivy.is_ivy_container(xs) else xs.copy() new_xs.insert(0, self.cont_copy()) return self.static_hstack( new_xs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_hstack( xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.hstack. This method simply wraps the function, and so the docstring for ivy.hstack also applies to this method with minimal changes. Examples -------- With one :class:`ivy.Container` input: >>> c = ivy.Container(a=[ivy.array([1,2,3]), ivy.array([0,0,0])]) >>> ivy.Container.static_hstack(c) { a: ivy.array([1, 2, 3, 0, 0, 0]) } """ return ContainerBase.cont_multi_map_in_function( "hstack", xs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_rot90( m: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, k: Optional[int] = 1, axes: Optional[Tuple[int, int]] = (0, 1), key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.rot90. This method simply wraps the function, and so the docstring for ivy.rot90 also applies to this method with minimal changes. Parameters ---------- m Input array of two or more dimensions. k Number of times the array is rotated by 90 degrees. axes The array is rotated in the plane defined by the axes. Axes must be different. key_chains The key-chains to apply or not apply the method to. Default is None. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container with a rotated view of m. Examples -------- >>> m = ivy.Container(a=ivy.array([[1,2], [3,4]]),\ b=ivy.array([[1,2,3,4],\ [7,8,9,10]])) >>> ivy.Container.static_rot90(m) { a: ivy.array([[2, 4], [1, 3]]), b: ivy.array([[4, 10], [3, 9], [2, 8], [1, 7]]) } """ return ContainerBase.cont_multi_map_in_function( "rot90", m, k=k, axes=axes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def rot90( self: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, k: Optional[int] = 1, axes: Optional[Tuple[int, int]] = (0, 1), key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.rot90. This method simply wraps the function, and so the docstring for ivy.rot90 also applies to this method with minimal changes. Parameters ---------- self Input array of two or more dimensions. k Number of times the array is rotated by 90 degrees. axes The array is rotated in the plane defined by the axes. Axes must be different. key_chains The key-chains to apply or not apply the method to. Default is None. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container with a rotated view of input array. Examples -------- >>> m = ivy.Container(a=ivy.array([[1,2], [3,4]]),\ b=ivy.array([[1,2,3,4],\ [7,8,9,10]])) >>> m.rot90() { a: ivy.array([[2, 4], [1, 3]]), b: ivy.array([[4, 10], [3, 9], [2, 8], [1, 7]]) } """ return self.static_rot90( self, k=k, axes=axes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_top_k( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], k: int, /, *, axis: Optional[int] = -1, largest: Optional[bool] = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Tuple[ivy.Container, ivy.Container]] = None, ) -> Tuple[ivy.Container, ivy.Container]: """ivy.Container static method variant of ivy.top_k. This method simply wraps the function, and so the docstring for ivy.top_k also applies to this method with minimal changes. Parameters ---------- x The container to compute top_k for. k Number of top elements to retun must not exceed the array size. axis The axis along which we must return the top elements default value is 1. largest If largest is set to False we return k smallest elements of the array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False`` out: Optional output tuple, for writing the result to. Must have two Container, with a shape that the returned tuple broadcast to. Returns ------- ret a container with indices and values. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, 2, -4]), b=ivy.array([4., 5., 0.])) >>> y = ivy.Container.static_top_k(x, 2) >>> print(y) { a: [ values = ivy.array([ 2, -1]), indices = ivy.array([1, 0]) ], b: [ values = ivy.array([5., 4.]), indices = ivy.array([1, 0]) ] } """ return ContainerBase.cont_multi_map_in_function( "top_k", x, k, axis=axis, largest=largest, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def top_k( self: ivy.Container, k: int, /, *, axis: Optional[int] = -1, largest: Optional[bool] = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Tuple[ivy.Container, ivy.Container]] = None, ) -> Tuple[ivy.Container, ivy.Container]: """ivy.Container instance method variant of ivy.top_k. This method simply wraps the function, and so the docstring for ivy.top_k also applies to this method with minimal changes. Parameters ---------- self The container to compute top_k for. k Number of top elements to retun must not exceed the array size. axis The axis along which we must return the top elements default value is 1. largest If largest is set to False we return k smallest elements of the array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False`` out: Optional output tuple, for writing the result to. Must have two Container, with a shape that the returned tuple broadcast to. Returns ------- ret a container with indices and values. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, 2, -4]), b=ivy.array([4., 5., 0.])) >>> y = x.top_k(2) >>> print(y) { a: [ values = ivy.array([ 2, -1]), indices = ivy.array([1, 0]) ], b: [ values = ivy.array([5., 4.]), indices = ivy.array([1, 0]) ] } """ return self.static_top_k( self, k, axis=axis, largest=largest, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_fliplr( m: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.fliplr. This method simply wraps the function, and so the docstring for ivy.fliplr also applies to this method with minimal changes. Parameters ---------- m the container with arrays to be flipped. Arrays must be at least 2-D. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False`` out optional output container, for writing the result to. Returns ------- ret container including arrays corresponding to the input container's array with elements order reversed along axis 1. Examples -------- With one :class:`ivy.Container` input: >>> m = ivy.Container(a=ivy.diag([1, 2, 3]),\ b=ivy.array([[1, 2, 3],[4, 5, 6]])) >>> ivy.Container.static_fliplr(m) { a: ivy.array([[0, 0, 1], [0, 2, 0], [3, 0, 0]]), b: ivy.array([[3, 2, 1], [6, 5, 4]]) } """ return ContainerBase.cont_multi_map_in_function( "fliplr", m, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def fliplr( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.fliplr. This method simply wraps the function, and so the docstring for ivy.fliplr also applies to this method with minimal changes. Parameters ---------- self the container with arrays to be flipped. Arrays must be at least 2-D. out optional output container, for writing the result to. Returns ------- ret container including arrays corresponding to the input container's array with elements order reversed along axis 1. Examples -------- With one :class:`ivy.Container` input: >>> m = ivy.Container(a=ivy.diag([1, 2, 3]),\ b=ivy.array([[1, 2, 3],[4, 5, 6]])) >>> m.fliplr() { a: ivy.array([[0, 0, 1], [0, 2, 0], [3, 0, 0]]), b: ivy.array([[3, 2, 1], [6, 5, 4]]) } """ return self.static_fliplr(self, out=out)
[docs]def static_i0( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.i0. This method simply wraps the function, and so the docstring for ivy.i0 also applies to this method with minimal changes. Parameters ---------- x the container with array inputs. out optional output container, for writing the result to. Returns ------- ret container including arrays with the modified Bessel function evaluated at each of the elements of x. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array(4)) >>> ivy.Container.static_i0(x) { a: ivy.array([1.26606588, 2.2795853 , 4.88079259]) b: ivy.array(11.30192195) } """ return ContainerBase.cont_multi_map_in_function( "i0", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def i0( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.i0. This method simply wraps the function, and so the docstring for ivy.i0 also applies to this method with minimal changes. Parameters ---------- self the container with array inputs. out optional output container, for writing the result to. Returns ------- ret container including arrays with the modified Bessel function evaluated at each of the elements of x. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array(4)) >>> x.i0() { a: ivy.array([1.26606588, 2.2795853 , 4.88079259]) b: ivy.array(11.30192195) } """ return self.static_i0(self, out=out)
[docs]def static_flatten( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, start_dim: Optional[int] = 0, end_dim: Optional[int] = -1, order: Optional[str] = "C", out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.flatten. This method simply wraps the function, and so the docstring for ivy.flatten also applies to this method with minimal changes. Parameters ---------- x input container to flatten at leaves. start_dim first dim to flatten. If not set, defaults to 0. end_dim last dim to flatten. If not set, defaults to -1. order Read the elements of the input container using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of indexing. Default order is 'C' Returns ------- ret Container with arrays flattened at leaves. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), ... b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])) >>> ivy.flatten(x) [{ a: ivy.array([1, 2, 3, 4, 5, 6, 7, 8]) b: ivy.array([9, 10, 11, 12, 13, 14, 15, 16]) }] >>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), ... b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])) >>> ivy.flatten(x, order="F") [{ a: ivy.array([1, 5, 3, 7, 2, 6, 4, 8]) b: ivy.array([9, 13, 11, 15, 10, 14, 12, 16]) }] """ return ContainerBase.cont_multi_map_in_function( "flatten", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, start_dim=start_dim, end_dim=end_dim, order=order, out=out, )
[docs]def flatten( self: ivy.Container, *, start_dim: Optional[int] = 0, end_dim: Optional[int] = -1, order: Optional[str] = "C", out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.flatten. This method simply wraps the function, and so the docstring for ivy.flatten also applies to this method with minimal changes. Parameters ---------- self input container to flatten at leaves. start_dim first dim to flatten. If not set, defaults to 0. end_dim last dim to flatten. If not set, defaults to -1. order Read the elements of the input container using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of indexing. Default order is 'C' Returns ------- ret Container with arrays flattened at leaves. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), ... b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])) >>> x.flatten() [{ a: ivy.array([1, 2, 3, 4, 5, 6, 7, 8]) b: ivy.array([9, 10, 11, 12, 13, 14, 15, 16]) }] >>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), ... b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])) >>> x.flatten(order="F") [{ a: ivy.array([1, 5, 3, 7, 2, 6, 4, 8]) b: ivy.array([9, 13, 11, 15, 10, 14, 12, 16]) }] """ return self.static_flatten( self, start_dim=start_dim, end_dim=end_dim, out=out, order=order )
[docs]def static_pad( input: ivy.Container, pad_width: Union[Iterable[Tuple[int]], int], /, *, mode: Optional[ Union[ Literal[ "constant", "edge", "linear_ramp", "maximum", "mean", "median", "minimum", "reflect", "symmetric", "wrap", "empty", ], Callable, ] ] = "constant", stat_length: Optional[Union[Iterable[Tuple[int]], int]] = None, constant_values: Optional[Union[Iterable[Tuple[Number]], Number]] = 0, end_values: Optional[Union[Iterable[Tuple[Number]], Number]] = 0, reflect_type: Optional[Literal["even", "odd"]] = "even", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **kwargs: Optional[Any], ) -> ivy.Container: """ ivy.Container static method variant of ivy.pad. This method simply wraps the function, and so the docstring for ivy.pad also applies to this method with minimal changes. """ return ContainerBase.cont_multi_map_in_function( "pad", input, pad_width, mode=mode, stat_length=stat_length, constant_values=constant_values, end_values=end_values, reflect_type=reflect_type, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **kwargs, )
[docs]def pad( self: ivy.Container, pad_width: Union[Iterable[Tuple[int]], int], /, *, mode: Optional[ Union[ Literal[ "constant", "edge", "linear_ramp", "maximum", "mean", "median", "minimum", "reflect", "symmetric", "wrap", "empty", ], Callable, ] ] = "constant", stat_length: Optional[Union[Iterable[Tuple[int]], int]] = None, constant_values: Optional[Union[Iterable[Tuple[Number]], Number]] = 0, end_values: Optional[Union[Iterable[Tuple[Number]], Number]] = 0, reflect_type: Optional[Literal["even", "odd"]] = "even", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **kwargs: Optional[Any], ) -> ivy.Container: """ ivy.Container instance method variant of ivy.pad. This method simply wraps the function, and so the docstring for ivy.pad also applies to this method with minimal changes. """ return self.static_pad( self, pad_width, mode=mode, stat_length=stat_length, constant_values=constant_values, end_values=end_values, reflect_type=reflect_type, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **kwargs, )
[docs]def static_vsplit( ary: Union[ivy.Array, ivy.NativeArray, ivy.Container], indices_or_sections: Union[int, Tuple[int]], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.vsplit. This method simply wraps the function, and so the docstring for ivy.vsplit also applies to this method with minimal changes. Parameters ---------- ary the container with array inputs. indices_or_sections If indices_or_sections is an integer n, the array is split into n sections. If the array is divisible by n vertically, each section will be of equal size. If input is not divisible by n, the sizes of the first int(ary.size(0) % n) sections will have size int(ary.size(0) / n) + 1, and the rest will have size int(ary.size(0) / n). If indices_or_sections is a tuple of ints, then input is split at each of the indices in the tuple. out optional output container, for writing the result to. Returns ------- ret container including input arrays split vertically. Examples -------- >>> ary = ivy.Container( a = ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b=ivy.array( [[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) ) ) >>> ivy.Container.static_vsplit(ary, 2) { a: [ivy.array([[[0., 1.], [2., 3.]]]), ivy.array([[[4., 5.], [6., 7.]]])], b: [ivy.array([[0., 1., 2., 3.], [4., 5., 6., 7.]]), ivy.array([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])] } """ return ContainerBase.cont_multi_map_in_function( "vsplit", ary, indices_or_sections=indices_or_sections, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def vsplit( self: ivy.Container, indices_or_sections: Union[int, Tuple[int]], /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.vsplit. This method simply wraps the function, and so the docstring for ivy.vsplit also applies to this method with minimal changes. Parameters ---------- self the container with array inputs. indices_or_sections If indices_or_sections is an integer n, the array is split into n sections. If the array is divisible by n vertically, each section will be of equal size. If input is not divisible by n, the sizes of the first int(ary.size(0) % n) sections will have size int(ary.size(0) / n) + 1, and the rest will have size int(ary.size(0) / n). If indices_or_sections is a tuple of ints, then input is split at each of the indices in the tuple. out optional output container, for writing the result to. Returns ------- ret container including arrays with the modified Bessel function evaluated at each of the elements of x. Examples -------- >>> ary = ivy.Container( a = ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b=ivy.array( [[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) ) ) >>> ary.vsplit(2) { a: [ivy.array([[[0., 1.], [2., 3.]]]), ivy.array([[[4., 5.], [6., 7.]]])], b: [ivy.array([[0., 1., 2., 3.], [4., 5., 6., 7.]]), ivy.array([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])] } """ return self.static_vsplit( self, indices_or_sections=indices_or_sections, out=out )
[docs]def static_dsplit( ary: Union[ivy.Array, ivy.NativeArray, ivy.Container], indices_or_sections: Union[int, Tuple[int]], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.dsplit. This method simply wraps the function, and so the docstring for ivy.dsplit also applies to this method with minimal changes. Parameters ---------- ary the container with array inputs. indices_or_sections If indices_or_sections is an integer n, the array is split into n sections. If the array is divisible by n along the 3rd axis, each section will be of equal size. If input is not divisible by n, the sizes of the first int(ary.size(0) % n) sections will have size int(ary.size(0) / n) + 1, and the rest will have size int(ary.size(0) / n). If indices_or_sections is a tuple of ints, then input is split at each of the indices in the tuple. out optional output container, for writing the result to. Returns ------- ret container including input arrays split along the 3rd axis. Examples -------- >>> ary = ivy.Container( a = ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b=ivy.array( [[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) ) ) >>> ivy.Container.static_dsplit(ary, 2) { a: [ivy.array([[[0., 1.], [2., 3.]]]), ivy.array([[[4., 5.], [6., 7.]]])], b: [ivy.array([[0., 1., 2., 3.], [4., 5., 6., 7.]]), ivy.array([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])] } """ return ContainerBase.cont_multi_map_in_function( "dsplit", ary, indices_or_sections=indices_or_sections, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def dsplit( self: ivy.Container, indices_or_sections: Union[int, Tuple[int]], /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.dsplit. This method simply wraps the function, and so the docstring for ivy.dsplit also applies to this method with minimal changes. Parameters ---------- self the container with array inputs. indices_or_sections If indices_or_sections is an integer n, the array is split into n sections. If the array is divisible by n along the 3rd axis, each section will be of equal size. If input is not divisible by n, the sizes of the first int(ary.size(0) % n) sections will have size int(ary.size(0) / n) + 1, and the rest will have size int(ary.size(0) / n). If indices_or_sections is a tuple of ints, then input is split at each of the indices in the tuple. out optional output container, for writing the result to. Returns ------- ret container including arrays with the modified Bessel function evaluated at each of the elements of x. Examples -------- >>> ary = ivy.Container( a = ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b=ivy.array( [[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) ) ) >>> ary.dsplit(2) { a: [ivy.array([[[0., 1.], [2., 3.]]]), ivy.array([[[4., 5.], [6., 7.]]])], b: [ivy.array([[0., 1., 2., 3.], [4., 5., 6., 7.]]), ivy.array([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])] } """ return self.static_dsplit( self, indices_or_sections=indices_or_sections, out=out )
[docs]def static_atleast_1d( *arys: Union[ivy.Array, ivy.NativeArray, ivy.Container], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> List[ivy.Container]: """ ivy.Container static method variant of ivy.atleast_1d. This method simply wraps the function, and so the docstring for ivy.atleast_1d also applies to this method with minimal changes. Parameters ---------- arys one or more container with array inputs. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret container or list of container where each elements within container is atleast 1d. Copies are made only if necessary. Examples -------- >>> ary = ivy.Container(a=ivy.array(1), b=ivy.array([3,4,5]),\ c=ivy.array([[3]])) >>> ivy.Container.static_atleast_1d(ary) { a: ivy.array([1]), b: ivy.array([3, 4, 5]), c: ivy.array([[3]]), } """ return ContainerBase.cont_multi_map_in_function( "atleast_1d", *arys, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def atleast_1d( self: Union[ivy.Container, ivy.Array, ivy.NativeArray], *arys: Union[ivy.Container, ivy.Array, ivy.NativeArray, bool, Number], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> List[ivy.Container]: """ ivy.Container instance method variant of ivy.atleast_1d. This method simply wraps the function, and so the docstring for ivy.atleast_1d also applies to this method with minimal changes. Parameters ---------- self the container with array inputs. arys one or more container with array inputs. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret container or list of container where each elements within container is atleast 1d. Copies are made only if necessary. Examples -------- >>> ary1 = ivy.Container(a=ivy.array(1), b=ivy.array([3,4]),\ c=ivy.array([[5]])) >>> ary2 = ivy.Container(a=ivy.array(9), b=ivy.array(2),\ c=ivy.array(3)) >>> ary1.atleast_1d(ary2) [{ a: ivy.array([1]), b: ivy.array([3, 4]), c: ivy.array([[5]]) }, { a: ivy.array([9]), b: ivy.array([2]), c: ivy.array([3]) }] """ return self.static_atleast_1d( self, *arys, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def dstack( self: ivy.Container, /, xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.stack. This method simply wraps the function, and so the docstring for ivy.stack also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]])) >>> x.dstack([y]) { a: ivy.array([[[0, 3], [1, 2]], [[2, 1], [3, 0]]]), b: ivy.array([[[4, 1]], [[5, 0]]]) } """ new_xs = xs.cont_copy() if ivy.is_ivy_container(xs) else xs.copy() new_xs.insert(0, self.cont_copy()) return self.static_dstack( new_xs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_dstack( xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.stack. This method simply wraps the function, and so the docstring for ivy.dstack also applies to this method with minimal changes. Examples -------- With one :class:`ivy.Container` input: >>> c = ivy.Container(a=[ivy.array([1,2,3]), ivy.array([0,0,0])], b=ivy.arange(3)) >>> ivy.Container.static_dstack(c) { a: ivy.array([[1, 0], [2, 0] [3,0]]), b: ivy.array([[0, 1, 2]) } """ return ContainerBase.cont_multi_map_in_function( "dstack", xs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_atleast_2d( *arys: Union[ivy.Array, ivy.NativeArray, ivy.Container], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> List[ivy.Container]: """ ivy.Container static method variant of ivy.atleast_2d. This method simply wraps the function, and so the docstring for ivy.atleast_2d also applies to this method with minimal changes. Parameters ---------- arys one or more container with array inputs. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret container or list of container where each elements within container is atleast 2D. Copies are made only if necessary. Examples -------- >>> ary = ivy.Container(a=ivy.array(1), b=ivy.array([3,4,5]),\ c=ivy.array([[3]])) >>> ivy.Container.static_atleast_2d(ary) { a: ivy.array([[1]]), b: ivy.array([[3, 4, 5]]), c: ivy.array([[3]]) } """ return ContainerBase.cont_multi_map_in_function( "atleast_2d", *arys, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def atleast_2d( self: Union[ivy.Container, ivy.Array, ivy.NativeArray], *arys: Union[ivy.Container, ivy.Array, ivy.NativeArray], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> List[ivy.Container]: """ivy.Container instance method variant of ivy.atleast_2d. This method simply wraps the function, and so the docstring for ivy.atleast_2d also applies to this method with minimal changes. Parameters ---------- self container with array inputs. arys one or more container with array inputs. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret container or list of container where each elements within container is atleast 2D. Copies are made only if necessary. Examples -------- >>> ary1 = ivy.Container(a=ivy.array(1), b=ivy.array([3,4]),\ c=ivy.array([[5]])) >>> ary2 = ivy.Container(a=ivy.array(9), b=ivy.array(2),\ c=ivy.array(3)) >>> ary1.atleast_2d(ary2) [{ a: ivy.array([[1]]), b: ivy.array([[3, 4]]), c: ivy.array([[5]]) }, { a: ivy.array([[9]]), b: ivy.array([[2]]), c: ivy.array([[3]]) }] """ return self.static_atleast_2d( self, *arys, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_atleast_3d( *arys: Union[ivy.Array, ivy.NativeArray, ivy.Container], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> List[ivy.Container]: """ ivy.Container static method variant of ivy.atleast_3d. This method simply wraps the function, and so the docstring for ivy.atleast_3d also applies to this method with minimal changes. Parameters ---------- arys one or more container with array inputs. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret container or list of container where each elements within container is atleast 3D. Copies are made only if necessary. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1), and a 2-D array of shape (M, N) becomes a view of shape (M, N, 1). Examples -------- >>> ary = ivy.Container(a=ivy.array(1), b=ivy.array([3,4,5]),\ c=ivy.array([[3]])) >>> ivy.Container.static_atleast_3d(ary) { a: ivy.array([[[1]]]), b: ivy.array([[[3], [4], [5]]]), c: ivy.array([[[3]]]) } """ return ContainerBase.cont_multi_map_in_function( "atleast_3d", *arys, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def atleast_3d( self: Union[ivy.Container, ivy.Array, ivy.NativeArray], *arys: Union[ivy.Container, ivy.Array, ivy.NativeArray, bool, Number], key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> List[ivy.Container]: """ivy.Container instance method variant of ivy.atleast_3d. This method simply wraps the function, and so the docstring for ivy.atleast_3d also applies to this method with minimal changes. Parameters ---------- self container with array inputs. arys one or more container with array inputs. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret container or list of container where each elements within container is atleast 3D. Copies are made only if necessary. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1), and a 2-D array of shape (M, N) becomes a view of shape (M, N, 1). Examples -------- >>> ary1 = ivy.Container(a=ivy.array(1), b=ivy.array([3,4]),\ c=ivy.array([[5]])) >>> ary2 = ivy.Container(a=ivy.array(9), b=ivy.array(2),\ c=ivy.array(3)) >>> ary1.atleast_3d(ary2) [{ a: ivy.array([[[1]]]), b: ivy.array([[[3], [4]]]), c: ivy.array([[[5]]]) }, { a: ivy.array([[[9]]]), b: ivy.array([[[2]]]), c: ivy.array([[[3]]]) }] """ return self.static_atleast_3d( self, *arys, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_take_along_axis( arr: Union[ivy.Array, ivy.NativeArray, ivy.Container], indices: Union[ivy.Array, ivy.NativeArray, ivy.Container], axis: int, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.take_along_axis. This method simply wraps the function, and so the docstring for ivy.take_along_axis also applies to this method with minimal changes. Parameters ---------- arr container with array inputs. indices container with indices of the values to extract. axis The axis over which to select values. If axis is None, then arr and indices must be 1-D sequences of the same length. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. Returns ------- ret a container with arrays of the same shape as those in indices. Examples -------- >>> arr = ivy.Container(a=ivy.array([[1, 2], [3, 4]]),\ b=ivy.array([[5, 6], [7, 8]])) >>> indices = ivy.Container(a=ivy.array([[0, 0], [1, 1]]),\ b=ivy.array([[1, 0], [1, 0]])) >>> ivy.Container.static_take_along_axis(arr, indices, axis=1) { a: ivy.array([[1, 1], [4, 4]]), b: ivy.array([[6, 5], [8, 7]]) } """ return ContainerBase.cont_multi_map_in_function( "take_along_axis", arr, indices, axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def take_along_axis( self: Union[ivy.Container, ivy.Array, ivy.NativeArray], indices: Union[ivy.Container, ivy.Array, ivy.NativeArray], axis: int, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.take_along_axis. This method simply wraps the function, and so the docstring for ivy.take_along_axis also applies to this method with minimal changes. Parameters ---------- self container with array inputs. indices container with indices of the values to extract. axis The axis over which to select values. If axis is None, then arr and indices must be 1-D sequences of the same length. key_chains The keychains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. Returns ------- ret a container with arrays of the same shape as those in indices. Examples -------- >>> arr = ivy.Container(a=ivy.array([[1, 2], [3, 4]]),\ b=ivy.array([[5, 6], [7, 8]])) >>> indices = ivy.Container(a=ivy.array([[0, 0], [1, 1]]),\ b=ivy.array([[1, 0], [1, 0]])) >>> arr.take_along_axis(indices, axis=1) [{ a: ivy.array([[1, 1], [4, 4]]), b: ivy.array([[6, 5], [8, 7]]) }] """ return self.static_take_along_axis( self, indices, axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_hsplit( ary: Union[ivy.Array, ivy.NativeArray, ivy.Container], indices_or_sections: Union[int, Tuple[int]], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.hsplit. This method simply wraps the function, and so the docstring for ivy.hsplit also applies to this method with minimal changes. Parameters ---------- ary the container with array inputs. indices_or_sections If indices_or_sections is an integer n, the array is split into n sections. If the array is divisible by n horizontally, each section will be of equal size. If input is not divisible by n, the sizes of the first int(ary.size(0) % n) sections will have size int(ary.size(0) / n) + 1, and the rest will have size int(ary.size(0) / n). If indices_or_sections is a tuple of ints, then input is split at each of the indices in the tuple. out optional output container, for writing the result to. Returns ------- ret container including input arrays split horizontally. Examples -------- >>> ary = ivy.Container( a = ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b=ivy.array( [[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) ) ) >>> ivy.Container.static_vsplit(ary, 2) { a: ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b: [ivy.array([[ 0., 1.], [ 4., 5.], [ 8., 9.], [12., 13.]]), ivy.array([[ 2., 3.], [ 6., 7.], [10., 11.], [14., 15.]]) } """ return ContainerBase.cont_multi_map_in_function( "hsplit", ary, indices_or_sections, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def hsplit( self: ivy.Container, indices_or_sections: Union[int, Tuple[int]], /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.hsplit. This method simply wraps the function, and so the docstring for ivy.hsplit also applies to this method with minimal changes. Parameters ---------- self the container with array inputs. indices_or_sections If indices_or_sections is an integer n, the array is split into n sections. If the array is divisible by n horizontally, each section will be of equal size. If input is not divisible by n, the sizes of the first int(ary.size(0) % n) sections will have size int(ary.size(0) / n) + 1, and the rest will have size int(ary.size(0) / n). If indices_or_sections is a tuple of ints, then input is split at each of the indices in the tuple. out optional output container, for writing the result to. Returns ------- ret container including arrays with the modified Bessel function evaluated at each of the elements of x. Examples -------- >>> ary = ivy.Container( a = ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b=ivy.array( [[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) ) ) >>> ary.hsplit(2) { a: ivy.ivy.array( [[[0., 1.], [2., 3.]], [[4., 5.], [6., 7.]]] ), b: [ivy.array([[ 0., 1.], [ 4., 5.], [ 8., 9.], [12., 13.]]), ivy.array([[ 2., 3.], [ 6., 7.], [10., 11.], [14., 15.]]) } """ return self.static_hsplit(self, indices_or_sections, out=out)
[docs]def static_broadcast_shapes( shapes: Union[ivy.Container, List[Tuple[int]]], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.broadcast_shapes. This method simply wraps the function, and so the docstring for ivy.hsplit also applies to this method with minimal changes. Parameters ---------- shapes the container with shapes to broadcast. Returns ------- ret Container with broadcasted shapes. Examples -------- >>> shapes = ivy.Container(a = [(2, 3), (2, 1)], ... b = [(2, 3), (1, 3)], ... c = [(2, 3), (2, 3)], ... d = [(2, 3), (2, 1), (1, 3), (2, 3)]) >>> z = ivy.Container.static_broadcast_shapes(shapes) >>> print(z) { a: (2, 3), b: (2, 3), c: (2, 3), d: (2, 3) } """ return ContainerBase.cont_multi_map_in_function( "broadcast_shapes", shapes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def broadcast_shapes( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.broadcast_shapes. This method simply wraps the function, and so the docstring for ivy.broadcast_shapes also applies to this method with minimal changes. Parameters ---------- self the container with shapes to broadcast. Returns ------- ret Container with broadcasted shapes. Examples -------- >>> shapes = ivy.Container(a = [(2, 3), (2, 1)], ... b = [(2, 3), (1, 3)], ... c = [(2, 3), (2, 3)], ... d = [(2, 3), (2, 1), (1, 3), (2, 3)]) >>> z = shapes.broadcast_shapes() >>> print(z) { a: (2, 3), b: (2, 3), c: (2, 3), d: (2, 3) } """ return self.static_broadcast_shapes(self, out=out)
[docs]def static_logit( x: Union[float, int, ivy.Container], /, *, eps: Optional[float] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.logit. This method simply wraps the function, and so the docstring for ivy.logit also applies to this method with minimal changes. Parameters ---------- x Input container. eps When eps is None the function outpus NaN where x < 0 or x > 1. and inf or -inf where x = 1 or x = 0, respectively. Otherwise if eps is defined, x is clamped to [eps, 1 - eps] out Optional output Contaner. Returns ------- ret Container with logits of the leaves. Examples -------- >>> a = ivy.array([1, 0, 0.9]) >>> b = ivy.array([0.1, 2, -0.9]) >>> x = ivy.Container(a=a, b=b) >>> z = ivy.Container.static_logit(x) >>> print(z) { a: ivy.array([inf, -inf, 2.19722438]), b: ivy.array([-2.19722462, nan, nan]) } >>> a = ivy.array([0.3, 2, 0.9]) >>> b = ivy.array([0.1, 1.2, -0.9]) >>> x = ivy.Container(a=a, b=b) >>> z = ivy.Container.static_logit(x, eps=0.2) >>> print(z) { a: ivy.array([-0.84729779, 1.38629448, 1.38629448]), b: ivy.array([-1.38629436, 1.38629448, -1.38629436]) } """ return ContainerBase.cont_multi_map_in_function( "logit", x, eps=eps, out=out, )
[docs]def logit( self: Union[float, int, ivy.Container], /, *, eps: Optional[float] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.logit. This method simply wraps the function, and so the docstring for ivy.logit also applies to this method with minimal changes. Parameters ---------- self Input container. eps When eps is None the function outpus NaN where x < 0 or x > 1. and inf or -inf where x = 1 or x = 0, respectively. Otherwise if eps is defined, x is clamped to [eps, 1 - eps] out Optional output Contaner. Returns ------- ret Container with logits of the leaves. Examples -------- >>> a = ivy.array([1, 0, 0.9]) >>> b = ivy.array([0.1, 2, -0.9]) >>> x = ivy.Container(a=a, b=b) >>> z = x.logit() >>> print(z) { a: ivy.array([inf, -inf, 2.19722438]), b: ivy.array([-2.19722462, nan, nan]) } >>> a = ivy.array([0.3, 2, 0.9]) >>> b = ivy.array([0.1, 1.2, -0.9]) >>> x = ivy.Container(a=a, b=b) >>> z = x.logit(eps=0.2) >>> print(z) { a: ivy.array([-0.84729779, 1.38629448, 1.38629448]), b: ivy.array([-1.38629436, 1.38629448, -1.38629436]) } """ return self.static_logit(self, eps=eps, out=out)
[docs]def static_binary_cross_entropy_with_logits( true: Union[ivy.Array, ivy.NativeArray], pred: Union[ivy.Array, ivy.NativeArray], /, *, epsilon: float = 1e-7, pos_weight: Optional[Union[ivy.Array, ivy.NativeArray]] = None, reduction: str = "none", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.binary_cross_entropy_with_logits. This method simply wraps the function, and so the docstring for ivy.binary_cross_entropy_with_logits also applies to this method with minimal changes. Parameters ---------- true input container of true labels. pred input container of predicted labels as logits. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. pos_weight a weight for positive examples. Must be an array with length equal to the number of classes. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The binary cross entropy with logits loss between the given distributions. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 1, 0]),b=ivy.array([0, 0, 1])) >>> y = ivy.Container(a=ivy.array([3.6, 1.2, 5.3]),b=ivy.array([1.8, 2.2, 1.2])) >>> z = ivy.Container.static_binary_cross_entropy_with_logits(x, y) >>> print(z) { a: ivy.array([0.027, 0.263, 5.305]), b: ivy.array([1.953, 2.305, 0.263]) } """ return ContainerBase.cont_multi_map_in_function( "static_binary_cross_entropy_with_logits", true, pred, epsilon=epsilon, pos_weight=pos_weight, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def binary_cross_entropy_with_logits( self: Union[ivy.Array, ivy.NativeArray], pred: Union[ivy.Array, ivy.NativeArray], /, *, epsilon: float = 1e-7, pos_weight: Optional[Union[ivy.Array, ivy.NativeArray]] = None, reduction: str = "none", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container method variant of ivy.binary_cross_entropy_with_logits. This method simply wraps the function, and so the docstring for ivy.binary_cross_entropy_with_logits also applies to this method with minimal changes. Parameters ---------- self input container of true labels. pred input container of predicted labels as logits. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. pos_weight a weight for positive examples. Must be an array with length equal to the number of classes. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The binary cross entropy with logits loss between the given distributions. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 1, 0]),b=ivy.array([0, 0, 1])) >>> y = ivy.Container(a=ivy.array([3.6, 1.2, 5.3]),b=ivy.array([1.8, 2.2, 1.2])) >>> z = x.binary_cross_entropy_with_logits(y) >>> print(z) { a: ivy.array([0.027, 0.263, 5.305]), b: ivy.array([1.953, 2.305, 0.263]) } """ return self.static_binary_cross_entropy_with_logits( self, pred, epsilon=epsilon, pos_weight=pos_weight, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_median( input: ivy.Container, /, *, axis: Optional[Union[Tuple[int], int]] = None, keepdims: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.median. This method simply wraps the function, and so the docstring for ivy.median also applies to this method with minimal changes. Parameters ---------- input Input container including arrays. axis Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. out optional output array, for writing the result to. Returns ------- ret The median of the array elements. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.zeros((3, 4, 5)), b=ivy.zeros((2,7,6))) >>> ivy.Container.static_moveaxis(x, 0, -1).shape { a: (4, 5, 3) b: (7, 6, 2) } """ return ContainerBase.cont_multi_map_in_function( "median", input, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def median( self: ivy.Container, /, *, axis: Optional[Union[Tuple[int], int]] = None, keepdims: Optional[bool] = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.median. This method simply wraps the function, and so the docstring for ivy.median also applies to this method with minimal changes. Parameters ---------- self Input container including arrays. axis Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. out optional output array, for writing the result to. Returns ------- ret The median of the array elements. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container( >>> a=ivy.array([[10, 7, 4], [3, 2, 1]]), >>> b=ivy.array([[1, 4, 2], [8, 7, 0]]) >>> ) >>> x.median(axis=0) { a: ivy.array([6.5, 4.5, 2.5]), b: ivy.array([4.5, 5.5, 1.]) } """ return self.static_median(self, axis=axis, keepdims=keepdims, out=out)
[docs]def static_nanmean( input: ivy.Container, /, *, axis: Optional[Union[Tuple[int], int]] = None, keepdims: Optional[bool] = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.nanmean. This method simply wraps the function, and so the docstring for ivy.nanmean also applies to this method with minimal changes. Parameters ---------- input Input container including arrays. axis Axis or axes along which the means are computed. The default is to compute the mean of the flattened array. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised. dtype The desired data type of returned tensor. Default is None. out optional output array, for writing the result to. Returns ------- ret The nanmean of the array elements in the container. Examples -------- >>> a = ivy.Container(x=ivy.array([[1, ivy.nan], [3, 4]]),\ y=ivy.array([[ivy.nan, 1, 2], [1, 2, 3]]) >>> ivy.Container.static_moveaxis(a) { x: 2.6666666666666665 y: 1.8 } """ return ContainerBase.cont_multi_map_in_function( "nanmean", input, axis=axis, keepdims=keepdims, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def nanmean( self: ivy.Container, /, *, axis: Optional[Union[Tuple[int], int]] = None, keepdims: Optional[bool] = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.nanmean. This method simply wraps the function, and so the docstring for ivy.nanmean also applies to this method with minimal changes. Parameters ---------- self Input container including arrays. axis Axis or axes along which the means are computed. The default is to compute the mean of the flattened array. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised. dtype The desired data type of returned tensor. Default is None. out optional output array, for writing the result to. Returns ------- ret The nanmean of the array elements in the input container. Examples -------- >>> a = ivy.Container(x=ivy.array([[1, ivy.nan], [3, 4]]),\ y=ivy.array([[ivy.nan, 1, 2], [1, 2, 3]]) >>> a.nanmean() { x: 2.6666666666666665 y: 1.8 } """ return self.static_nanmean( self, axis=axis, keepdims=keepdims, dtype=dtype, out=out )
[docs]def static_unravel_index( indices: ivy.Container, shape: Tuple[int], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.unravel_index. This method simply wraps the function, and so the docstring for ivy.unravel_index also applies to this method with minimal changes. Parameters ---------- input Input container including arrays. shape The shape of the array to use for unraveling indices. out optional output array, for writing the result to. Returns ------- ret Container with tuples that have arrays with the same shape as the arrays in the input container. Examples -------- With one :class:`ivy.Container` input: >>> indices = ivy.Container(a=ivy.array([22, 41, 37])), b=ivy.array([30, 2])) >>> ivy.Container.static_unravel_index(indices, (7,6)) { a: (ivy.array([3, 6, 6]), ivy.array([4, 5, 1])) b: (ivy.array([5, 0], ivy.array([0, 2]))) } """ return ContainerBase.cont_multi_map_in_function( "unravel_index", indices, shape=shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def unravel_index( self: ivy.Container, shape: Tuple[int], /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.unravel_index. This method simply wraps the function, and so the docstring for ivy.unravel_index also applies to this method with minimal changes. Parameters ---------- self Input container including arrays. shape The shape of the array to use for unraveling indices. out optional output array, for writing the result to. Returns ------- ret Container with tuples that have arrays with the same shape as the arrays in the input container. Examples -------- With one :class:`ivy.Container` input: >>> indices = ivy.Container(a=ivy.array([22, 41, 37])), b=ivy.array([30, 2])) >>> indices.unravel_index((7, 6)) { a: (ivy.array([3, 6, 6]), ivy.array([4, 5, 1])) b: (ivy.array([5, 0], ivy.array([0, 2]))) } """ return self.static_unravel_index(self, shape, out=out)
[docs]def static_quantile( a: Union[ivy.Container, ivy.Array, ivy.NativeArray], q: Union[ivy.Array, float], /, *, axis: Optional[Union[Sequence[int], int]] = None, keepdims: bool = False, interpolation: str = "linear", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.quantile. This method simply wraps the function, and so the docstring for ivy.quantile also applies to this method with minimal changes. Parameters ---------- a Input container including arrays. q Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive. axis Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a. interpolation {'nearest', 'linear', 'lower', 'higher', 'midpoint'}. Default value: 'linear'. This specifies the interpolation method to use when the desired quantile lies between two data points i < j: - linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j. - lower: i. - higher: j. - nearest: i or j, whichever is nearest. - midpoint: (i + j) / 2. linear and midpoint interpolation do not work with integer dtypes. out optional output array, for writing the result to. Returns ------- ret Container with (rank(q) + N - len(axis)) dimensional arrays of same dtype as input arrays in the container, or, if axis is None, rank(q) arrays. The first rank(q) dimensions index quantiles for different values of q. Examples -------- With one :class:`ivy.Container` input: >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]), y=ivy.array([1., 2., 3., 4.])) >>> q = 0.5 >>> b = ivy.Container.static_quantile(a, q) >>> print(b) { x: 3.5, y: 2.5 } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]), y=ivy.array([1., 2., 3., 4.])) >>> q = ivy.array([0.5, 0.75]) >>> b = ivy.Container.static_quantile(a, q) >>> print(b) { x: ivy.array([3.5, 6.25]), y: ivy.array([2.5, 3.25]) } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]), y=ivy.array([1., 2., 3., 4.])) >>> q = ivy.array([0.5, 0.75]) >>> b = ivy.Container.static_quantile(a, q, axis = 0) >>> print(b) { x: ivy.array([[6.5, 4.5, 2.5], [8.25, 5.75, 3.25]]), y: ivy.array([2.5, 3.25]) } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]])) >>> b = ivy.Container.static_quantile(a, q, axis = 1, keepdims=True) >>> print(b) { x: ivy.array([[[7.], [2.]], [[8.5], [2.5]]]) } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]), y=ivy.array([1., 2., 3., 4.])) >>> q = ivy.array([0.3, 0.7]) >>> b = ivy.Container.static_quantile(a, q, axis = 0, interpolation="lower") >>> print(b) { x: ivy.array([[3., 2., 1.], [3., 2., 1.]]), y: ivy.array([1., 3.]) } """ return ContainerBase.cont_multi_map_in_function( "quantile", a, q, axis=axis, keepdims=keepdims, interpolation=interpolation, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def quantile( self: ivy.Container, q: Union[ivy.Array, float], /, *, axis: Optional[Union[Sequence[int], int]] = None, keepdims: bool = False, interpolation: str = "linear", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.quantile. This method simply wraps the function, and so the docstring for ivy.quantile also applies to this method with minimal changes. Parameters ---------- a Input container including arrays. q Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive. axis Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a. interpolation {'nearest', 'linear', 'lower', 'higher', 'midpoint'}. Default value: 'linear'. This specifies the interpolation method to use when the desired quantile lies between two data points i < j: - linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j. - lower: i. - higher: j. - nearest: i or j, whichever is nearest. - midpoint: (i + j) / 2. linear and midpoint interpolation do not work with integer dtypes. out optional output array, for writing the result to. Returns ------- ret Container with (rank(q) + N - len(axis)) dimensional arrays of same dtype as input arrays in the container, or, if axis is None, rank(q) arrays. The first rank(q) dimensions index quantiles for different values of q. Examples -------- With one :class:`ivy.Container` input: >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]),\ y=ivy.array([1., 2., 3., 4.])) >>> q = 0.5 >>> b = a.quantile(q) >>> print(b) { x: 3.5, y: 2.5 } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]), y=ivy.array([1., 2., 3., 4.])) >>> q = ivy.array([0.5, 0.75]) >>> b = a.quantile(q) >>> print(b) { x: ivy.array([3.5, 6.25]), y: ivy.array([2.5, 3.25]) } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]), y=ivy.array([1., 2., 3., 4.])) >>> q = ivy.array([0.5, 0.75]) >>> b = a.quantile(q, axis = 0) >>> print(b) { x: ivy.array([[6.5, 4.5, 2.5], [8.25, 5.75, 3.25]]), y: ivy.array([2.5, 3.25]) } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]])) >>> b = a.quantile(q, axis = 1, keepdims=True) >>> print(b) { x: ivy.array([[[7.], [2.]], [[8.5], [2.5]]]) } >>> a = ivy.Container(x=ivy.array([[10., 7., 4.], [3., 2., 1.]]), y=ivy.array([1., 2., 3., 4.])) >>> q = ivy.array([0.3, 0.7]) >>> b = a.quantile(q, axis = 0, interpolation="lower") >>> print(b) { x: ivy.array([[3., 2., 1.], [3., 2., 1.]]), y: ivy.array([1., 3.]) } """ return self.static_quantile( self, q, axis=axis, keepdims=keepdims, interpolation=interpolation, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_corrcoef( x: ivy.Container, /, *, y: ivy.Container = None, rowvar: Optional[bool] = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = False, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.corrcoef. This method simply wraps the function, and so the docstring for ivy.corrcoef also applies to this method with minimal changes. Parameters ---------- x Input container including arrays. y An additional input container. rowvar If rowvar is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations. Returns ------- ret The corrcoef of the array elements in the container. Examples -------- >>> a = ivy.Container(w=ivy.array([[1., 2.], [3., 4.]]), \ z=ivy.array([[0., 1., 2.], [2., 1., 0.]])) >>> ivy.Container.corrcoef(a) { w: ivy.array([[1., 1.], [1., 1.]]), z: ivy.array([[1., -1.], [-1., 1.]]) } """ return ContainerBase.cont_multi_map_in_function( "corrcoef", x, y=y, rowvar=rowvar, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def corrcoef( self: ivy.Container, /, *, y: ivy.Container = None, rowvar: Optional[bool] = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.corrcoef. This method simply wraps the function, and so the docstring for ivy.corrcoef also applies to this method with minimal changes. Parameters ---------- self Input container including arrays. y An additional input container. rowvar If rowvar is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations. Returns ------- ret The corrcoef of the array elements in the input container. Examples -------- >>> a = ivy.Container(w=ivy.array([[1., 2.], [3., 4.]]), \ z=ivy.array([[0., 1., 2.], [2., 1., 0.]])) >>> ivy.Container.corrcoef(a) { w: ivy.array([[1., 1.], [1., 1.]]), z: ivy.array([[1., -1.], [-1., 1.]]) } """ return self.static_corrcoef(self, y=y, rowvar=rowvar, out=out)
[docs]def static_max_pool1d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[int, Tuple[int]], strides: Union[int, Tuple[int]], padding: str, /, *, data_format: str = "NWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.max_pool1d. This method simply wraps the function, and so the docstring for ivy.max_pool1d also applies to this method with minimal changes. Parameters ---------- x Container of input images *[batch_size, w, d_in]*. kernel Size of the kernel i.e., the sliding window for each dimension of input. *[w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NWC" or "NCW". Defaults to "NWC". out optional output array, for writing the result to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12.).reshape((2,2,3)) >>> b = ivy.arange(24.).reshape((2,3,4)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(ivy.Container.static_max_pool1d(x,2, 2, "VALID")) { a: ivy.array([[[3., 4., 5.]], [[9., 10., 11.]]]), b: ivy.array([[[4., 5., 6., 7.]], [[16., 17., 18., 19.]]]) } """ return ContainerBase.cont_multi_map_in_function( "max_pool1d", x, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def max_pool1d( self: ivy.Container, kernel: Union[int, Tuple[int]], strides: Union[int, Tuple[int]], padding: str, /, *, data_format: str = "NWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of `ivy.max_pool1d`. This method simply wraps the function, and so the docstring for `ivy.max_pool1d` also applies to this method with minimal changes. Parameters ---------- self Container of input images *[batch_size, w, d_in]*. kernel Size of the kernel i.e., the sliding window for each dimension of input. *[w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NWC" or "NCW". Defaults to "NWC". out optional output array, for writing the result to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12.).reshape((2,2,3)) >>> b = ivy.arange(24.).reshape((2,3,4)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(x.max_pool1d(2, 2, "VALID")) { a: ivy.array([[[3., 4., 5.]], [[9., 10., 11.]]]), b: ivy.array([[[4., 5., 6., 7.]], [[16., 17., 18., 19.]]]) } """ return self.static_max_pool1d( self, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_max_pool2d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[int, Tuple[int], Tuple[int, int]], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, data_format: str = "NHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.max_pool2dd. This method simply wraps the function, and so the docstring for ivy.max_pool2d also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,h,w,d_in]*. kernel The size of the window to take a max over. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 4, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(ivy.Container.static_max_pool2d(x, (2, 2), (1, 1), "SAME")) { a: (<class ivy.array.array.Array> shape=[2, 1, 3, 2]), b: (<class ivy.array.array.Array> shape=[2, 4, 3, 2]) } """ return ContainerBase.cont_multi_map_in_function( "max_pool2d", x, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def max_pool2d( self: ivy.Container, kernel: Union[int, Tuple[int], Tuple[int, int]], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, data_format: str = "NHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of `ivy.max_pool2d`. This method simply wraps the function, and so the docstring for `ivy.max_pool2d` also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,h,w,d_in]*. kernel The size of the window to take a max over. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 4, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(x.max_pool2d((2, 2), (1, 1), "SAME")) { a: (<class ivy.array.array.Array> shape=[2, 1, 3, 2]), b: (<class ivy.array.array.Array> shape=[2, 4, 3, 2]) } """ return self.static_max_pool2d( self, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_max_pool3d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[int, Tuple[int], Tuple[int, int, int]], strides: Union[int, Tuple[int], Tuple[int, int, int]], padding: str, /, *, data_format: str = "NDHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.max_pool3d. This method simply wraps the function, and so the docstring for ivy.max_pool3d also applies to this method with minimal changes. Parameters ---------- x Input volume *[batch_size,d,h,w,d_in]*. kernel Convolution filters *[d,h,w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NDHWC" or "NCDHW". Defaults to "NDHWC". out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((1, 2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 2, 2, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(ivy.Container.static_max_pool3d(x, 2, 1, "VALID")) { a: ivy.array([], shape=(1, 1, 0, 2, 2)), b: ivy.array([[[[[20, 21], [22, 23]]]], [[[[44, 45], [46, 47]]]]]) } """ return ContainerBase.cont_multi_map_in_function( "max_pool3d", x, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def max_pool3d( self: ivy.Container, kernel: Union[int, Tuple[int], Tuple[int, int, int]], strides: Union[int, Tuple[int], Tuple[int, int, int]], padding: str, /, *, data_format: str = "NDHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.max_pool3d. This method simply wraps the function, and so the docstring for ivy.max_pool3d also applies to this method with minimal changes. Parameters ---------- x Input volume *[batch_size,d,h,w,d_in]*. kernel Convolution filters *[d,h,w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NDHWC" or "NCDHW". Defaults to "NDHWC". out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((1, 2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 2, 2, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(x.max_pool3d(2, 1, "VALID")) { a: ivy.array([], shape=(1, 1, 0, 2, 2)), b: ivy.array([[[[[20, 21], [22, 23]]]], [[[[44, 45], [46, 47]]]]]) } """ return self.static_max_pool3d( self, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_avg_pool1d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[int, Tuple[int]], strides: Union[int, Tuple[int]], padding: str, /, *, data_format: str = "NWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.avg_pool1d. This method simply wraps the function, and so the docstring for ivy.avg_pool1d also applies to this method with minimal changes. Parameters ---------- x Container of input images *[batch_size, w, d_in]*. kernel Size of the kernel i.e., the sliding window for each dimension of input. *[w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NWC" or "NCW". Defaults to "NWC". out optional output array, for writing the result to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12.).reshape((2,2,3)) >>> b = ivy.arange(24.).reshape((2,3,4)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(ivy.Container.static_avg_pool1d(x,2, 2, "VALID")) { a: ivy.array([[[1.5, 2.5, 3.5]], [[7.5, 8.5, 9.5]]]), b: ivy.array([[[2., 3., 4., 5.]], [[14., 15., 16., 17.]]]) } """ return ContainerBase.cont_multi_map_in_function( "avg_pool1d", x, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def avg_pool1d( self: ivy.Container, kernel: Union[int, Tuple[int]], strides: Union[int, Tuple[int]], padding: str, /, *, data_format: str = "NWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of `ivy.avg_pool1d`. This method simply wraps the function, and so the docstring for `ivy.avg_pool1d` also applies to this method with minimal changes. Parameters ---------- self Container of input images *[batch_size, w, d_in]*. kernel Size of the kernel i.e., the sliding window for each dimension of input. *[w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NWC" or "NCW". Defaults to "NWC". out optional output array, for writing the result to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12.).reshape((2,2,3)) >>> b = ivy.arange(24.).reshape((2,3,4)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(x.avg_pool1d(2, 2, "VALID")) { a: ivy.array([[[1.5, 2.5, 3.5]], [[7.5, 8.5, 9.5]]]), b: ivy.array([[[2., 3., 4., 5.]], [[14., 15., 16., 17.]]]) } """ return self.static_avg_pool1d( self, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_avg_pool2d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[int, Tuple[int], Tuple[int, int]], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, data_format: str = "NHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.avg_pool2d. This method simply wraps the function, and so the docstring for ivy.avg_pool2d also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,h,w,d_in]*. kernel The size of the window to take a max over. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 4, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(ivy.Container.static_avg_pool2d(x, (2, 2), (1, 1), "SAME")) { a: ivy.array([], shape=(2, 0, 2, 2)), b: (<class ivy.array.array.Array> shape=[2, 3, 2, 2]) } """ return ContainerBase.cont_multi_map_in_function( "avg_pool2d", x, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def avg_pool2d( self: ivy.Container, kernel: Union[int, Tuple[int], Tuple[int, int]], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, data_format: str = "NHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of `ivy.avg_pool2d`. This method simply wraps the function, and so the docstring for `ivy.avg_pool2d` also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,h,w,d_in]*. kernel The size of the window to take a max over. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 4, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(x.avg_pool2d((2, 2), (1, 1), "SAME")) { a: (<class ivy.array.array.Array> shape=[2, 1, 3, 2]), b: (<class ivy.array.array.Array> shape=[2, 4, 3, 2]) } """ return self.static_avg_pool2d( self, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_avg_pool3d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[int, Tuple[int], Tuple[int, int, int]], strides: Union[int, Tuple[int], Tuple[int, int, int]], padding: str, /, *, data_format: str = "NDHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.avg_pool3d. This method simply wraps the function, and so the docstring for ivy.avg_pool3d also applies to this method with minimal changes. Parameters ---------- x Input volume *[batch_size,d,h,w,d_in]*. kernel Convolution filters *[d,h,w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NDHWC" or "NCDHW". Defaults to "NDHWC". out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((1, 2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 2, 2, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(ivy.Container.static_avg_pool3d(x, 2, 1, "VALID")) { a: ivy.array([], shape=(1, 1, 0, 2, 2)), b: ivy.array([[[[[10., 11.], [12., 13.]]]], [[[[34., 35.], [36., 37.]]]]]) } """ return ContainerBase.cont_multi_map_in_function( "avg_pool3d", x, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def avg_pool3d( self: ivy.Container, kernel: Union[int, Tuple[int], Tuple[int, int, int]], strides: Union[int, Tuple[int], Tuple[int, int, int]], padding: str, /, *, data_format: str = "NDHWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.avg_pool3d. This method simply wraps the function, and so the docstring for ivy.avg_pool3d also applies to this method with minimal changes. Parameters ---------- x Input volume *[batch_size,d,h,w,d_in]*. kernel Convolution filters *[d,h,w]*. strides The stride of the sliding window for each dimension of input. padding SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format NDHWC" or "NCDHW". Defaults to "NDHWC". out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the pooling operation. Examples -------- >>> a = ivy.arange(12).reshape((1, 2, 1, 3, 2)) >>> b = ivy.arange(48).reshape((2, 2, 2, 3, 2)) >>> x = ivy.Container({'a': a, 'b': b}) >>> print(x.max_pool3d(2, 1, "VALID")) { a: ivy.array([], shape=(1, 1, 0, 2, 2)), b: ivy.array([[[[[20, 21], [22, 23]]]], [[[[44, 45], [46, 47]]]]]) } """ return self.static_avg_pool3d( self, kernel, strides, padding, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_dct( x: ivy.Container, /, *, type: Optional[Literal[1, 2, 3, 4]] = 2, n: Optional[int] = None, axis: Optional[int] = -1, norm: Optional[Literal["ortho"]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.dct. This method simply wraps the function, and so the docstring for ivy.dct also applies to this method with minimal changes. Parameters ---------- x Container with the input signals. type The type of the dct. Must be 1, 2, 3 or 4. n The lenght of the transform. If n is less than the input signal lenght, then x is truncated, if n is larger than x is zero-padded. norm The type of normalization to be applied. Must be either None or "ortho". out optional output container, for writing the result to. Returns ------- ret The transformed input. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([8, 16, 24, 32, 40, 48, 56, 64]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8])) >>> ivy.Container.static_dct(x, type=2, norm='ortho') { a: ivy.array([102., -51.5, 0., -5.39, 0., -1.61, 0., -0.406]), b: ivy.array([12.7, -6.44, 0., -0.673, 0., -0.201, 0., -0.0507]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([ 8, 16, 24, 32, 40, 48, 56, 64]), ... b=ivy.array([11., 54, 23., 13., 255., 255., 132., 182.])) >>> n = ivy.Container(a=9, b=5) >>> type = ivy.Container(a=2, b=4) >>> norm = ivy.Container(a="ortho", b=None) >>> ivy.Container.static_dct(x, type=type, n=n, norm=norm) { a: ivy.array([96., -28.2, -31.9, 22.9, -26., 19.8, -17., 10.9, -5.89]), b: ivy.array([242., -253., 286., -515., 467.]) } """ return ContainerBase.cont_multi_map_in_function( "dct", x, type=type, n=n, axis=axis, norm=norm, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def dct( self: ivy.Container, /, *, type: Optional[Literal[1, 2, 3, 4]] = 2, n: Optional[int] = None, axis: Optional[int] = -1, norm: Optional[Literal["ortho"]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.dct. This method simply wraps the function, and so the docstring for ivy.dct also applies to this method with minimal changes. Parameters ---------- self Container with the input signals. type The type of the dct. Must be 1, 2, 3 or 4. n The lenght of the transform. If n is less than the input signal lenght, then x is truncated, if n is larger then x is zero-padded. norm The type of normalization to be applied. Must be either None or "ortho". out optional output container, for writing the result to. Returns ------- ret The transformed input. Examples -------- >>> x = ivy.Container(a=ivy.array([8, 16, 24, 32, 40, 48, 56, 64]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8])) >>> x.dct(type=2, norm='ortho') { a: ivy.array([102., -51.5, 0., -5.39, 0., -1.61, 0., -0.406]), b: ivy.array([12.7, -6.44, 0., -0.673, 0., -0.201, 0., -0.0507]) } """ return self.static_dct( self, type=type, n=n, axis=axis, norm=norm, out=out, )
[docs]def static_fft( x: ivy.Container, dim: int, /, *, norm: Optional[str] = "backward", n: Optional[Union[int, Tuple[int]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ): """ivy.Container static method variant of ivy.fft. This method simply wraps the function, and so the docstring for ivy.fft also applies to this method with minimal changes. Parameters ---------- x Container containing input volumes *[...,d_in,...]*, where d_in indicates the dimension that needs FFT. dim The dimension along which to take the one dimensional FFT. norm Optional argument, "backward", "ortho" or "forward". Defaults to be "backward". "backward" indicates no normalization. "ortho" indicates normalization by 1/sqrt(n). "forward" indicates normalization by 1/n. n Optional argument indicating the sequence length, if given, the input would be padded with zero or truncated to length n before performing FFT. Should be a integer greater than 1. out Optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The transformed input. Examples -------- >>> a = ivy.array(np.array([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])) >>> b = ivy.array(np.exp(2j * np.pi * np.arange(8) / 8)) >>> c = ivy.Container(a=a, b=b) >>> dims = ivy.Container(a=0, b=0) >>> ivy.Container.static_fft(c, dims) { a: ivy.array([0.+0.j, 12.+0.j, 8.+0.j, 4.+0.j]), b: ivy.array([-3.44509285e-16+1.14423775e-17j, 8.00000000e+00-8.11483250e-16j, 2.33486982e-16+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j, 9.95799250e-17+2.33486982e-16j, 0.00000000e+00+7.66951701e-17j, 1.14423775e-17+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j]) } """ return ContainerBase.cont_multi_map_in_function( "fft", x, dim, norm=norm, n=n, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def fft( self: ivy.Container, dim: int, /, *, norm: Optional[str] = "backward", n: Optional[Union[int, Tuple[int]]] = None, out: Optional[ivy.Array] = None, ): """ivy.Container instance method variant of ivy.fft. This method simply wraps the function, and so the docstring for ivy.fft also applies to this method with minimal changes. Parameters ---------- self Container containing input volumes *[...,d_in,...]*, where d_in indicates the dimension that needs FFT. dim The dimension along which to take the one dimensional FFT. norm Optional argument, "backward", "ortho" or "forward". Defaults to be "backward". "backward" indicates no normalization. "ortho" indicates normalization by 1/sqrt(n). "forward" indicates normalization by 1/n. n Optional argument indicating the sequence length, if given, the input would be padded with zero or truncated to length n before performing FFT. Should be a integer greater than 1. out Optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container containing the transformed inputs. Examples -------- >>> a = ivy.array(np.array([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])) >>> b = ivy.array(np.exp(2j * np.pi * np.arange(8) / 8)) >>> c = ivy.Container(a=a, b=b) >>> dims = ivy.Container(a=0, b=0) >>> c.fft(dims) { a: ivy.array([0.+0.j, 12.+0.j, 8.+0.j, 4.+0.j]), b: ivy.array([-3.44509285e-16+1.14423775e-17j, 8.00000000e+00-8.11483250e-16j, 2.33486982e-16+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j, 9.95799250e-17+2.33486982e-16j, 0.00000000e+00+7.66951701e-17j, 1.14423775e-17+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j]) } """ return self.static_fft( self, dim, norm=norm, n=n, out=out, )
[docs]def static_ifft( x: ivy.Container, dim: int, *, norm: Optional[str] = "backward", n: Optional[Union[int, Tuple[int]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ): """ivy.Container static method variant of ivy.ifft. This method simply wraps the function, and so the docstring for ivy.ifft also applies to this method with minimal changes. Parameters ---------- x Container containing input volumes *[...,d_in,...]*, where d_in indicates the dimension that needs IFFT. dim The dimension along which to take the one dimensional IFFT. norm Optional argument, "backward", "ortho" or "forward". Defaults to be "backward". "backward" indicates no normalization. "ortho" indicates normalization by 1/sqrt(n). "forward" indicates normalization by 1/n. n Optional argument indicating the sequence length, if given, the input would be padded with zero or truncated to length n before performing IFFT. Should be a integer greater than 1. out Optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The transformed input. Examples -------- >>> a = ivy.array(np.array([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])) >>> b = ivy.array(np.exp(2j * np.pi * np.arange(8) / 8)) >>> c = ivy.Container(a=a, b=b) >>> dims = ivy.Container(a=0, b=0) >>> ivy.Container.static_ifft(c, dims) { a: ivy.array([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j]), b: ivy.array([-4.30636606e-17+1.43029718e-18j, 0.00000000e+00+1.53080850e-17j, 1.43029718e-18+1.53080850e-17j, 0.00000000e+00+9.58689626e-18j, 1.24474906e-17+2.91858728e-17j, 0.00000000e+00+1.53080850e-17j, 2.91858728e-17+1.53080850e-17j, 1.00000000e+00-1.01435406e-16j]) } """ return ContainerBase.cont_multi_map_in_function( "ifft", x, dim, norm=norm, n=n, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def ifft( self: ivy.Container, dim: int, *, norm: Optional[str] = "backward", n: Optional[Union[int, Tuple[int]]] = None, out: Optional[ivy.Array] = None, ): """ivy.Container instance method variant of ivy.ifft. This method simply wraps the function, and so the docstring for ivy.ifft also applies to this method with minimal changes. Parameters ---------- self Container containing input volumes *[...,d_in,...]*, where d_in indicates the dimension that needs IFFT. dim The dimension along which to take the one dimensional IFFT. norm Optional argument, "backward", "ortho" or "forward". Defaults to be "backward". "backward" indicates no normalization. "ortho" indicates normalization by 1/sqrt(n). "forward" indicates normalization by 1/n. n Optional argument indicating the sequence length, if given, the input would be padded with zero or truncated to length n before performing IFFT. Should be a integer greater than 1. out Optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Container containing the transformed inputs. Examples -------- >>> a = ivy.array(np.array([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])) >>> b = ivy.array(np.exp(2j * np.pi * np.arange(8) / 8)) >>> c = ivy.Container(a=a, b=b) >>> dims = ivy.Container(a=0, b=0) >>> c.ifft(dims) { a: ivy.array([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j]), b: ivy.array([-4.30636606e-17+1.43029718e-18j, 0.00000000e+00+1.53080850e-17j, 1.43029718e-18+1.53080850e-17j, 0.00000000e+00+9.58689626e-18j, 1.24474906e-17+2.91858728e-17j, 0.00000000e+00+1.53080850e-17j, 2.91858728e-17+1.53080850e-17j, 1.00000000e+00-1.01435406e-16j]) } """ return self.static_ifft( self, dim, norm=norm, n=n, out=out, )
[docs]def static_diagflat( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, offset: Optional[int] = 0, padding_value: Optional[float] = 0, align: Optional[str] = "RIGHT_LEFT", num_rows: Optional[int] = -1, num_cols: Optional[int] = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "diagflat", x, offset=offset, padding_value=padding_value, align=align, num_rows=num_rows, num_cols=num_cols, out=out, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def diagflat( self: ivy.Container, /, *, offset: Optional[int] = 0, padding_value: Optional[float] = 0, align: Optional[str] = "RIGHT_LEFT", num_rows: Optional[int] = -1, num_cols: Optional[int] = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.diagflat. This method simply wraps the function, and so the docstring for ivy.diagflat also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=[1,2]) >>> ivy.diagflat(x, k=1) { a: ivy.array([[0, 1, 0], [0, 0, 2], [0, 0, 0]]) } """ return self.static_diagflat( self, offset=offset, padding_value=padding_value, align=align, num_rows=num_rows, num_cols=num_cols, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_kron( a: Union[ivy.Array, ivy.NativeArray, ivy.Container], b: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.kron. This method simply wraps the function, and so the docstring for ivy.kron also applies to this method with minimal changes. Parameters ---------- a first container with input arrays. b second container with input arrays out optional output container, for writing the result to. Returns ------- ret container including arrays corresponding to the Kronecker product of the arrays in the input containers, computed element-wise Examples -------- >>> a = ivy.Container(x=ivy.array([1,2]), y=ivy.array(50)) >>> b = ivy.Container(x=ivy.array([3,4]), y=ivy.array(9)) >>> ivy.Container.static_kron(a, b) { a: ivy.array([3, 4, 6, 8]) b: ivy.array([450]) } """ return ContainerBase.cont_multi_map_in_function( "kron", a, b, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def kron( self: ivy.Container, b: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.kron. This method simply wraps the function, and so the docstring for ivy.kron also applies to this method with minimal changes. Examples -------- >>> a = ivy.Container(x=ivy.array([1,2]), y=ivy.array([50])) >>> b = ivy.Container(x=ivy.array([3,4]), y=ivy.array(9)) >>> a.kron(b) { a: ivy.array([3, 4, 6, 8]) b: ivy.array([450]) } """ return self.static_kron( self, b, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_matrix_exp( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "matrix_exp", x, out=out, key_chains=key_chains, to_apply=to_apply, )
[docs]def matrix_exp( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.diagflat. This method simply wraps the function, and so the docstring for ivy.diagflat also applies to this method with minimal changes. Examples -------- >>> x = ivy.array([[[1., 0.], [0., 1.]], [[2., 0.], [0., 2.]]]) >>> ivy.matrix_exp(x) ivy.array([[[2.7183, 1.0000], [1.0000, 2.7183]], [[7.3891, 1.0000], [1.0000, 7.3891]]]) """ return self.static_matrix_exp( self, key_chains=key_chains, to_apply=to_apply, out=out, )
[docs]def static_eig( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.eig. This method simply wraps the function, and so the docstring for ivy.eig also applies to this method with minimal changes. Parameters ---------- x container with input arrays. Returns ------- ret container including tuple of arrays corresponding to eigenvealues and eigenvectors of input array Examples -------- >>> x = ivy.array([[1,2], [3,4]]) >>> c = ivy.Container({'x':{'xx':x}}) >>> ivy.Container.eig(c) { x: { xx: (tuple(2), <class ivy.array.array.Array>, shape=[2, 2]) } } >>> ivy.Container.eig(c)['x']['xx'] ( ivy.array([-0.37228107+0.j, 5.3722816 +0.j]), ivy.array([ [-0.8245648 +0.j, -0.41597357+0.j], [0.56576747+0.j, -0.9093767 +0.j] ]) ) """ return ContainerBase.cont_multi_map_in_function( "eig", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def eig( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.eig. This method simply wraps the function, and so the docstring for ivy.eig also applies to this method with minimal changes. Parameters ---------- x container with input arrays. Returns ------- ret container including arrays corresponding eigenvealues and eigenvectors of input arrays Examples -------- >>> x = ivy.array([[1,2], [3,4]]) >>> c = ivy.Container({'x':{'xx':x}}) >>> c.eig() { x: { xx: (tuple(2), <class ivy.array.array.Array>, shape=[2, 2]) } } >>>c.eig()['x']['xx'] ( ivy.array([-0.37228107+0.j, 5.3722816 +0.j]), ivy.array([ [-0.8245648 +0.j, -0.41597357+0.j], [0.56576747+0.j, -0.9093767 +0.j] ]) ) """ return self.static_eig( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_eigvals( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.eigvals. This method simply wraps the function, and so the docstring for ivy.eigvals also applies to this method with minimal changes. Parameters ---------- x container with input arrays. Returns ------- ret container including array corresponding to eigenvalues of input array Examples -------- >>> x = ivy.array([[1,2], [3,4]]) >>> c = ivy.Container({'x':{'xx':x}}) >>> ivy.Container.eigvals(c) { x: { xx: ivy.array([-0.37228132+0.j, 5.37228132+0.j]) } } >>> ivy.Container.eigvals(c)['x']['xx'] ivy.array([-0.37228132+0.j, 5.37228132+0.j]) """ return ContainerBase.cont_multi_map_in_function( "eigvals", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def eigvals( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.eigvals. This method simply wraps the function, and so the docstring for ivy.eigvals also applies to this method with minimal changes. Parameters ---------- x container with input arrays. Returns ------- ret container including array corresponding to eigenvalues of input array Examples -------- >>> x = ivy.array([[1,2], [3,4]]) >>> c = ivy.Container({'x':{'xx':x}}) >>> c.eigvals() { x: { xx: ivy.array([-0.37228132+0.j, 5.37228132+0.j]) } } >>> c.eigvals()['x']['xx'] ivy.array([-0.37228132+0.j, 5.37228132+0.j]) """ return self.static_eigvals( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_adjoint( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, out: Optional[ivy.Container] = None, ): """ ivy.Container static method variant of ivy.adjoint. This method simply wraps the function, and so the docstring for ivy.adjoint also applies to this method with minimal changes. Parameters ---------- x container with input arrays of dimensions greater than 1. out optional output container, for writing the result to. Returns ------- ret container including arrays corresponding to the conjugate transpose of the arrays in the input container Examples -------- >>> x = np.array([[1.-1.j, 2.+2.j], [3.+3.j, 4.-4.j]]) >>> y = np.array([[1.-2.j, 3.+4.j], [1.-0.j, 2.+6.j]]) >>> c = ivy.Container(a=ivy.array(x), b=ivy.array(y)) >>> ivy.Container.static_adjoint(c) { a: ivy.array([[1.+1.j, 3.-3.j], [2.-2.j, 4.+4.j]]), b: ivy.array([[1.+2.j, 1.-0.j], [3.-4.j, 2.-6.j]]) } """ return ContainerBase.cont_multi_map_in_function( "adjoint", x, out=out, key_chains=key_chains, to_apply=to_apply, )
[docs]def adjoint( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, out: Optional[ivy.Container] = None, ): """ ivy.Container instance method variant of ivy.adjoint. This method simply wraps the function, and so the docstring for ivy.adjoint also applies to this method with minimal changes. Examples -------- >>> x = np.array([[1.-1.j, 2.+2.j], [3.+3.j, 4.-4.j]]) >>> c = ivy.Container(a=ivy.array(x)) >>> c.adjoint() { a: ivy.array([[1.+1.j, 3.-3.j], [2.-2.j, 4.+4.j]]) } """ return self.static_adjoint( self, key_chains=key_chains, to_apply=to_apply, out=out )
[docs]def static_sinc( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sinc. This method simply wraps the function, and so the docstring for ivy.sinc also applies to this method with minimal changes. Parameters ---------- x input container whose elements are each expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the sinc of each element in ``x``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0.5, 1.5, 2.5]), ... b=ivy.array([3.5, 4.5, 5.5])) >>> y = ivy.Container.static_sinc(x) >>> print(y) { a: ivy.array([0.636, -0.212, 0.127]), b: ivy.array([-0.090, 0.070, -0.057]) } """ return ContainerBase.cont_multi_map_in_function( "sinc", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sinc( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sinc. This method simply wraps the function, and so the docstring for ivy.sinc also applies to this method with minimal changes. Parameters ---------- self input container whose elements are each expressed in radians. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the sinc of each element in ``self``. The returned container must have a floating-point data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([0.5, 1.5, 2.5]), ... b=ivy.array([3.5, 4.5, 5.5])) >>> y = x.sinc() >>> print(y) { a: ivy.array([0.637,-0.212,0.127]), b: ivy.array([-0.0909,0.0707,-0.0579]) } """ return self.static_sinc( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_lcm( x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.lcm. This method simply wraps the function, and so the docstring for ivy.lcm also applies to this method with minimal changes. Parameters ---------- x1 first input container. x2 second input container. out optional output container, for writing the result to. Returns ------- ret a container containing the element-wise least common multiples of the arrays contained in x1 and x2. Examples -------- >>> x1=ivy.Container(a=ivy.array([2, 3, 4]), ... b=ivy.array([6, 54, 62, 10])) >>> x2=ivy.Container(a=ivy.array([5, 8, 15]), ... b=ivy.array([32, 40, 25, 13])) >>> ivy.Container.lcm(x1, x2) { a: ivy.array([10, 21, 60]), b: ivy.array([96, 1080, 1550, 130]) } """ return ContainerBase.cont_multi_map_in_function( "lcm", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def lcm( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.lcm. This method simply wraps the function, and so the docstring for ivy.lcm also applies to this method with minimal changes. Parameters ---------- x1 first input container. x2 second input container. out optional output container, for writing the result to. Returns ------- ret a container containing the the element-wise least common multiples of the arrays contained in x1 and x2. Examples -------- >>> x1=ivy.Container(a=ivy.array([2, 3, 4]), ... b=ivy.array([6, 54, 62, 10])) >>> x2=ivy.Container(a=ivy.array([5, 8, 15]), ... b=ivy.array([32, 40, 25, 13])) >>> x1.lcm(x2) { a: ivy.array([10, 24, 60]), b: ivy.array([96, 1080, 1550, 130]) } """ return self.static_lcm( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_fmod( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.fmod. This method simply wraps the function, and so the docstring for ivy.fmod also applies to this method with minimal changes. Parameters ---------- x1 container with the first input arrays. x2 container with the second input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise remainder of divisions. Examples -------- >>> x1 = ivy.Container(a=ivy.array([2, 3, 4]),\ b=ivy.array([ivy.nan, 0, ivy.nan])) >>> x2 = ivy.Container(a=ivy.array([1, 5, 2]),\ b=ivy.array([0, ivy.nan, ivy.nan])) >>> ivy.Container.static_fmod(x1, x2) { a: ivy.array([ 0, 3, 0]) b: ivy.array([ nan, nan, nan]) } """ return ContainerBase.cont_multi_map_in_function( "fmod", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def fmod( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.fmod. This method simply wraps the function, and so the docstring for ivy.fmod also applies to this method with minimal changes. Parameters ---------- self container with the first input arrays. x2 container with the second input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise remainder of divisions. Examples -------- >>> x1 = ivy.Container(a=ivy.array([2, 3, 4]),\ b=ivy.array([ivy.nan, 0, ivy.nan])) >>> x2 = ivy.Container(a=ivy.array([1, 5, 2]),\ b=ivy.array([0, ivy.nan, ivy.nan])) >>> x1.fmod(x2) { a: ivy.array([ 0, 3, 0]) b: ivy.array([ nan, nan, nan]) } """ return self.static_fmod(self, x2, out=out)
[docs]def static_fmax( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.fmax. This method simply wraps the function, and so the docstring for ivy.fmax also applies to this method with minimal changes. Parameters ---------- x1 container with the first input arrays. x2 container with the second input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise maximums. Examples -------- >>> x1 = ivy.Container(a=ivy.array([2, 3, 4]),\ b=ivy.array([ivy.nan, 0, ivy.nan])) >>> x2 = ivy.Container(a=ivy.array([1, 5, 2]),\ b=ivy.array([0, ivy.nan, ivy.nan])) >>> ivy.Container.static_fmax(x1, x2) { a: ivy.array([ 2., 5., 4.]) b: ivy.array([ 0, 0, nan]) } """ return ContainerBase.cont_multi_map_in_function( "fmax", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def fmax( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.fmax. This method simply wraps the function, and so the docstring for ivy.fmax also applies to this method with minimal changes. Parameters ---------- self container with the first input arrays. x2 container with the second input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise maximums. Examples -------- >>> x1 = ivy.Container(a=ivy.array([2, 3, 4]),\ b=ivy.array([ivy.nan, 0, ivy.nan])) >>> x2 = ivy.Container(a=ivy.array([1, 5, 2]),\ b=ivy.array([0, ivy.nan, ivy.nan])) >>> x1.fmax(x2) { a: ivy.array([ 2., 5., 4.]) b: ivy.array([ 0, 0, nan]) } """ return self.static_fmax(self, x2, out=out)
[docs]def static_fmin( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.fmin. This method simply wraps the function, and so the docstring for ivy.fmin also applies to this method with minimal changes. Parameters ---------- x1 container with the first input arrays. x2 container with the second input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise minimums. Examples -------- >>> x1 = ivy.Container(a=ivy.array([2, 3, 4]),\ b=ivy.array([ivy.nan, 0, ivy.nan])) >>> x2 = ivy.Container(a=ivy.array([1, 5, 2]),\ b=ivy.array([0, ivy.nan, ivy.nan])) >>> ivy.Container.static_fmin(x1, x2) { a: ivy.array([1, 3, 2]), b: ivy.array([0., 0., nan]) } """ return ContainerBase.cont_multi_map_in_static_method( "fmin", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def fmin( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.fmin. This method simply wraps the function, and so the docstring for ivy.fmin also applies to this method with minimal changes. Parameters ---------- self container with the first input arrays. x2 container with the second input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise minimums. Examples -------- >>> x1 = ivy.Container(a=ivy.array([2, 3, 4]),\ b=ivy.array([ivy.nan, 0, ivy.nan])) >>> x2 = ivy.Container(a=ivy.array([1, 5, 2]),\ b=ivy.array([0, ivy.nan, ivy.nan])) >>> x1.fmin(x2) { a: ivy.array([1, 3, 2]), b: ivy.array([0., 0., nan]) } """ return self.static_fmin(self, x2, out=out)
[docs]def static_float_power( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, list, tuple], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.float_power. This method simply wraps the function, and so the docstring for ivy.float_power also applies to this method with minimal changes. Parameters ---------- x1 container with the base input arrays. x2 container with the exponent input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with base arrays raised to the powers of exponents arrays, element-wise . Examples -------- >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),\ b=ivy.array([2, 10])) >>> x2 = ivy.Container(a=ivy.array([1, 3, 1]), b=0) >>> ivy.Container.static_float_power(x1, x2) { a: ivy.array([1, 8, 3]) b: ivy.array([1, 1]) } """ return ContainerBase.cont_multi_map_in_function( "float_power", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def float_power( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.float_power. This method simply wraps the function, and so the docstring for ivy.float_power also applies to this method with minimal changes. Parameters ---------- self container with the base input arrays. x2 container with the exponent input arrays out optional output container, for writing the result to. Returns ------- ret Container including arrays with base arrays raised to the powers of exponents arrays, element-wise . Examples -------- >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),\ b=ivy.array([2, 10])) >>> x2 = ivy.Container(a=ivy.array([1, 3, 1]), b=0) >>> x1.float_power(x2) { a: ivy.array([1, 8, 3]) b: ivy.array([1, 1]) } """ return self.static_float_power(self, x2, out=out)
[docs]def static_exp2( x: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.exp2. This method simply wraps the function, and so the docstring for ivy.exp2 also applies to this method with minimal changes. Parameters ---------- x container with the base input arrays. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise 2 to the power of input arrays elements. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 3]),\ b=[5, 6, 7]) >>> ivy.Container.static_exp2(x) { a: ivy.array([2., 4., 8.]) b: ivy.array([32., 64., 128.]) } """ return ContainerBase.cont_multi_map_in_function( "exp2", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def exp2( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.exp2. This method simply wraps the function, and so the docstring for ivy.exp2 also applies to this method with minimal changes. Parameters ---------- self container with the base input arrays. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise 2 to the power of input array elements. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 3]),\ b=[5, 6, 7]) >>> x.exp2() { a: ivy.array([2., 4., 8.]) b: ivy.array([32., 64., 128.]) } """ return self.static_exp2(self, out=out)
[docs]def static_copysign( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container, Number], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container, Number], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.copysign. This method simply wraps the function, and so the docstring for ivy.copysign also applies to this method with minimal changes. Parameters ---------- x1 Container, Array, or scalar to change the sign of x2 Container, Array, or scalar from which the new signs are applied Unsigned zeroes are considered positive. out optional output Container, for writing the result to. Returns ------- ret x1 with the signs of x2. This is a scalar if both x1 and x2 are scalars. Examples -------- >>> x1 = ivy.Container(a=ivy.array([0,1,2]), b=ivy.array(-1)) >>> x2 = ivy.Container(a=-1, b=ivy.array(10)) >>> ivy.Container.static_copysign(x1, x2) { a: ivy.array([-0., -1., -2.]), b: ivy.array(1.) } >>> ivy.Container.static_copysign(23, x1) { a: ivy.array([23., 23., 23.]), b: ivy.array(-23.) } """ return ContainerBase.cont_multi_map_in_function( "copysign", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def copysign( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.copysign. This method simply wraps the function, and so the docstring for ivy.copysign also applies to this method with minimal changes. Parameters ---------- self Container to change the sign of x2 Container from which the new signs are applied Unsigned zeroes are considered positive. out optional output Container, for writing the result to. Returns ------- ret x1 with the signs of x2. This is a scalar if both x1 and x2 are scalars. Examples -------- >>> x1 = ivy.Container(a=ivy.array([0,1,2]), b=ivy.array(-1)) >>> x2 = ivy.Container(a=-1, b=ivy.array(10)) >>> x1.copysign(x2) { a: ivy.array([-0., -1., -2.]), b: ivy.array(1.) } >>> x1.copysign(-1) { a: ivy.array([-0., -1., -2.]), b: ivy.array(-1.) } """ return self.static_copysign(self, x2, out=out)
[docs]def static_count_nonzero( a: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: Optional[bool] = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.count_nonzero. This method simply wraps the function, and so the docstring for ivy.count_nonzero also applies to this method with minimal changes. Parameters ---------- a container with the base input arrays. axis optional axis or tuple of axes along which to count non-zeros. Default is None, meaning that non-zeros will be counted along a flattened version of the input array. keepdims optional, if this is set to True, the axes that are counted are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. dtype optional output dtype. Default is of type integer. key_chains The key-chains to apply or not apply the method to. Default is None. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. out optional output container, for writing the result to. Returns ------- ret Container including number of non-zero values in the array along a given axis. Otherwise, container with the total number of non-zero values in the array is returned. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1, 2, 3],[4, 5, 6, 7]]),\ b=ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])) >>> ivy.Container.static_count_nonzero(x) { a: ivy.array(7), b: ivy.array(7) } >>> x = ivy.Container(a=ivy.array([[0, 1, 2, 3],[4, 5, 6, 7]]),\ b=ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])) >>> ivy.Container.static_count_nonzero(x, axis=0) { a: ivy.array([1, 2, 2, 2]), b: ivy.array([[1, 2], [2, 2]]) } >>> x = ivy.Container(a=ivy.array([[0, 1, 2, 3],[4, 5, 6, 7]]),\ b=ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])) >>> ivy.Container.static_count_nonzero(x, axis=(0,1), keepdims=True) { a: ivy.array([[7]]), b: ivy.array([[[3, 4]]]) } """ return ContainerBase.cont_multi_map_in_function( "count_nonzero", a, axis=axis, keepdims=keepdims, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def count_nonzero( self: ivy.Container, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: Optional[bool] = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.count_nonzero. This method simply wraps the function, and so the docstring for ivy.count_nonzero also applies to this method with minimal changes. Parameters ---------- self container with the base input arrays. axis optional axis or tuple of axes along which to count non-zeros. Default is None, meaning that non-zeros will be counted along a flattened version of the input array. keepdims optional, if this is set to True, the axes that are counted are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. dtype optional output dtype. Default is of type integer. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False`` out optional output container, for writing the result to. Returns ------- ret Container including number of non-zero values in the array along a given axis. Otherwise, container with the total number of non-zero values in the array is returned. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1, 2, 3],[4, 5, 6, 7]]),\ b=ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])) >>> x.count_nonzero() { a: ivy.array(7), b: ivy.array(7) } >>> x = ivy.Container(a=ivy.array([[0, 1, 2, 3],[4, 5, 6, 7]]),\ b=ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])) >>> x.count_nonzero(axis=0) { a: ivy.array([1, 2, 2, 2]), b: ivy.array([[1, 2], [2, 2]]) } >>> x = ivy.Container(a=ivy.array([[0, 1, 2, 3],[4, 5, 6, 7]]),\ b=ivy.array([[[0,1],[2,3]],[[4,5],[6,7]]])) >>> x.count_nonzero(axis=(0,1), keepdims=True) { a: ivy.array([[7]]), b: ivy.array([[[3, 4]]]) } """ return self.static_count_nonzero( self, axis=axis, keepdims=keepdims, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_nansum( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Optional[Union[tuple, int]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, keepdims: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.nansum. This method simply wraps the function, and so the docstring for ivy.nansum also applies to this method with minimal changes. Parameters ---------- x Input array. axis Axis or axes along which the sum is computed. The default is to compute the sum of the flattened array. dtype The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of input is used. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. out Alternate output array in which to place the result. The default is None. Returns ------- ret A new array holding the result is returned unless out is specified, in which it is returned. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[10, 7, 4], [3, 2, 1]]),\ b=ivy.array([[1, 4, 2], [ivy.nan, ivy.nan, 0]])) >>> ivy.Container.static_nansum(x) { a: 27, b: 7.0 } >>> ivy.Container.static_nansum(x, axis=0) { a: ivy.array([13, 9, 5]), b: ivy.array([1., 4., 2.]) } >>> ivy.Container.static_nansum(x, axis=1) { a: ivy.array([21, 6]), b: ivy.array([7., 0.]) } """ return ContainerBase.cont_multi_map_in_function( "nansum", x, axis=axis, dtype=dtype, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def nansum( self: ivy.Container, /, *, axis: Optional[Union[tuple, int]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, keepdims: Optional[bool] = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.nansum. This method simply wraps the function, and so the docstring for ivy.nansum also applies to this method with minimal changes. Parameters ---------- self Input container including arrays. axis Axis or axes along which the sum is computed. The default is to compute the sum of the flattened array. dtype The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of input is used. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. out Alternate output array in which to place the result. The default is None. Returns ------- ret A new array holding the result is returned unless out is specified, in which it is returned. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[10, 7, 4], [3, 2, 1]]),\ b=ivy.array([[1, 4, 2], [ivy.nan, ivy.nan, 0]])) >>> x.nansum(axis=0) { a: ivy.array([13, 9, 5]), b: ivy.array([1., 4., 2.]) } >>> x.nansum(axis=1) { a: ivy.array([21, 6]), b: ivy.array([7., 0.]) } """ return self.static_nansum( self, axis=axis, dtype=dtype, keepdims=keepdims, out=out )
[docs]def static_gcd( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container, int, list, tuple], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container, int, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.gcd. This method simply wraps the function, and so the docstring for ivy.gcd also applies to this method with minimal changes. Parameters ---------- x1 first input container with array-like items. x2 second input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise gcd of input arrays. Examples -------- >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),\ b=ivy.array([1, 2, 3])) >>> x2 = ivy.Container(a=ivy.array([5, 6, 7]),\ b=10) >>> ivy.Container.static_gcd(x1, x2) { a: ivy.array([1., 1., 3.]) b: ivy.array([1., 2., 1.]) } """ return ContainerBase.cont_multi_map_in_function( "gcd", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def gcd( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.gcd. This method simply wraps the function, and so the docstring for ivy.gcd also applies to this method with minimal changes. Parameters ---------- self first input container with array-like items. x2 second input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise gcd of input arrays. Examples -------- >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),\ b=ivy.array([1, 2, 3])) >>> x2 = ivy.Container(a=ivy.array([5, 6, 7]),\ b=10) >>> x1.gcd(x2) { a: ivy.array([1., 1., 3.]) b: ivy.array([1., 2., 1.]) } """ return self.static_gcd(self, x2, out=out)
[docs]def static_isclose( a: Union[ivy.Container, ivy.Array, ivy.NativeArray], b: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, rtol: Optional[float] = 1e-05, atol: Optional[float] = 1e-08, equal_nan: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.isclose. This method simply wraps the function, and so the docstring for ivy.isclose also applies to this method with minimal changes. Parameters ---------- a Input container containing first input array. b Input container containing second input array. rtol The relative tolerance parameter. atol The absolute tolerance parameter. equal_nan Whether to compare NaN's as equal. If True, NaN's in a will be considered equal to NaN's in b in the output array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret A new array holding the result is returned unless out is specified, in which it is returned. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([1.0, ivy.nan]),\ b=ivy.array([1.0, ivy.nan])) >>> y = ivy.Container(a=ivy.array([1.0, ivy.nan]),\ b=ivy.array([1.0, ivy.nan])) >>> ivy.Container.static_isclose(x, y) { a: ivy.array([True, False]), b: ivy.array([True, False]) } >>> ivy.Container.static_isclose(x, y, equal_nan=True) { a: ivy.array([True, True]), b: ivy.array([True, True]) } >>> x = ivy.Container(a=ivy.array([1.0, 2.0]),\ b=ivy.array([1.0, 2.0])) >>> y = ivy.Container(a=ivy.array([1.0, 2.001]),\ b=ivy.array([1.0, 2.0])) >>> ivy.Container.static_isclose(x, y, atol=0.0) { a: ivy.array([True, False]), b: ivy.array([True, True]) } >>> ivy.Container.static_isclose(x, y, rtol=0.01, atol=0.0) { a: ivy.array([True, True]), b: ivy.array([True, True]) } """ return ContainerBase.cont_multi_map_in_function( "isclose", a, b, rtol=rtol, atol=atol, equal_nan=equal_nan, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def isclose( self: ivy.Container, b: ivy.Container, /, *, rtol: Optional[float] = 1e-05, atol: Optional[float] = 1e-08, equal_nan: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.isclose. This method simply wraps the function, and so the docstring for ivy.isclose also applies to this method with minimal changes. Parameters ---------- self Input container containing first input array. b Input container containing second input array. rtol The relative tolerance parameter. atol The absolute tolerance parameter. equal_nan Whether to compare NaN's as equal. If True, NaN's in a will be considered equal to NaN's in b in the output array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret A new array holding the result is returned unless out is specified, in which it is returned. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([1.0, ivy.nan]),\ b=ivy.array([1.0, ivy.nan])) >>> y = ivy.Container(a=ivy.array([1.0, ivy.nan]),\ b=ivy.array([1.0, ivy.nan])) >>> x.isclose(y) { a: ivy.array([True, False]), b: ivy.array([True, False]) } >>> x.isclose(y, equal_nan=True) { a: ivy.array([True, True]), b: ivy.array([True, True]) } >>> x = ivy.Container(a=ivy.array([1.0, 2.0]),\ b=ivy.array([1.0, 2.0])) >>> y = ivy.Container(a=ivy.array([1.0, 2.001]),\ b=ivy.array([1.0, 2.0])) >>> x.isclose(y, atol=0.0) { a: ivy.array([True, False]), b: ivy.array([True, True]) } >>> x.isclose(y, rtol=0.01, atol=0.0) { a: ivy.array([True, True]), b: ivy.array([True, True]) } """ return self.static_isclose( self, b, rtol=rtol, atol=atol, equal_nan=equal_nan, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_isposinf( x: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.isposinf. This method simply wraps the function, and so the docstring for ivy.isposinf also applies to this method with minimal changes. Parameters ---------- x container with the base input arrays. out optional output container, for writing the result to. Returns ------- ret Container including a boolean array with values True where the corresponding element of the input is positive infinity and values False where the element of the input is not positive infinity. Examples -------- >>> x = ivy.Container(a=ivy.array([1, ivy.inf, -ivy.inf]),\ b=ivy.array([5, ivy.inf, ivy.inf])) >>> ivy.Container.static_isposinf(x) { a: ivy.array([False, True, False]), b: ivy.array([False, True, True]) } """ return ContainerBase.cont_multi_map_in_function( "isposinf", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def isposinf( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.isposinf. This method simply wraps the function, and so the docstring for ivy.isposinf also applies to this method with minimal changes. Parameters ---------- self container with the base input arrays. out optional output container, for writing the result to. Returns ------- ret Returns container including a boolean array with values True where the corresponding element of the input is positive infinity and values False where the element of the input is not positive infinity. Examples -------- >>> x = ivy.Container(a=ivy.array([1, ivy.inf, -ivy.inf]),\ b=ivy.array([5, ivy.inf, ivy.inf])) >>> x.isposinf() { a: ivy.array([False, True, False]), b: ivy.array([False, True, True]) } """ return self.static_isposinf(self, out=out)
[docs]def static_isneginf( x: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.isneginf. This method simply wraps the function, and so the docstring for ivy.isneginf also applies to this method with minimal changes. Parameters ---------- x container with the base input arrays. out optional output container, for writing the result to. Returns ------- ret Container including a boolean array with values True where the corresponding element of the input is negative infinity and values False where the element of the input is not negative infinity. Examples -------- >>> x = ivy.Container(a=ivy.array([1, ivy.inf, -ivy.inf]),\ b=ivy.array([5, -ivy.inf, -ivy.inf])) >>> ivy.Container.static_isneginf(x) { a: ivy.array([False, False, True]), b: ivy.array([False, True, True]) } """ return ContainerBase.cont_multi_map_in_function( "isneginf", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def isneginf( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.isneginf. This method simply wraps the function, and so the docstring for ivy.isneginf also applies to this method with minimal changes. Parameters ---------- self container with the base input arrays. out optional output container, for writing the result to. Returns ------- ret Returns container including a boolean array with values True where the corresponding element of the input is negative infinity and values False where the element of the input is not negative infinity. Examples -------- >>> x = ivy.Container(a=ivy.array([1, ivy.inf, -ivy.inf]),\ b=ivy.array([5, -ivy.inf, -ivy.inf])) >>> x.isneginf() { a: ivy.array([False, False, True]), b: ivy.array([False, True, True]) } """ return self.static_isneginf(self, out=out)
[docs]def static_angle( z: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, deg: Optional[bool] = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.angle. This method simply wraps the function, and so the docstring for ivy.angle also applies to this method with minimal changes. Parameters ---------- z Array-like input. deg optional bool. out optional output array, for writing the result to. Returns ------- ret Returns an array of angles for each complex number in the input. If def is False(default), angle is calculated in radian and if def is True, then angle is calculated in degrees. Examples -------- >>> ivy.set_backend('tensorflow') >>> x = ivy.Container(a=ivy.array([-2.25 + 4.75j, 3.25 + 5.75j]), b=ivy.array([-2.25 + 4.75j, 3.25 + 5.75j])) >>> x { a: ivy.array([-2.25+4.75j, 3.25+5.75j]), b: ivy.array([-2.25+4.75j, 3.25+5.75j]) } >>> ivy.Container.static_angle(x) { a: ivy.array([2.01317055, 1.05634501]), b: ivy.array([2.01317055, 1.05634501]) } >>> ivy.set_backend('numpy') >>> ivy.Container.static_angle(x,deg=True) { a: ivy.array([115.3461759, 60.524111]), b: ivy.array([115.3461759, 60.524111]) } """ return ContainerBase.cont_multi_map_in_function( "angle", z, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, deg=deg, out=out, )
[docs]def angle( self: ivy.Container, /, *, deg: Optional[bool] = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.angle. This method simply wraps the function, and so the docstring for ivy.angle also applies to this method with minimal changes. Parameters ---------- z Array-like input. deg optional bool. out optional output array, for writing the result to. Returns ------- ret Returns an array of angles for each complex number in the input. If def is False(default), angle is calculated in radian and if def is True, then angle is calculated in degrees. Examples -------- >>> ivy.set_backend('tensorflow') >>> x = ivy.Container(a=ivy.array([-2.25 + 4.75j, 3.25 + 5.75j]), b=ivy.array([-2.25 + 4.75j, 3.25 + 5.75j])) >>> x { a: ivy.array([-2.25+4.75j, 3.25+5.75j]), b: ivy.array([-2.25+4.75j, 3.25+5.75j]) } >>> x.angle() { a: ivy.array([2.01317055, 1.05634501]), b: ivy.array([2.01317055, 1.05634501]) } >>> ivy.set_backend('numpy') >>> x.angle(deg=True) { a: ivy.array([115.3461759, 60.524111]), b: ivy.array([115.3461759, 60.524111]) } """ return self.static_angle(self, deg=deg, out=out)
[docs]def static_imag( val: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.imag. This method simply wraps the function, and so the docstring for ivy.imag also applies to this method with minimal changes. Parameters ---------- val Array-like input. out optional output array, for writing the result to. Returns ------- ret Returns an Container including arrays with the imaginary part of complex numbers. Examples -------- >>> x = ivy.Container(a=ivy.array(np.array([1+2j, 3+4j, 5+6j])), b=ivy.array(np.array([-2.25 + 4.75j, 3.25 + 5.75j]))) >>> x { a: ivy.array([1.+2.j, 3.+4.j, 5.+6.j]), b: ivy.array([-2.25+4.75j, 3.25+5.75j]) } >>> ivy.Container.static_imag(x) { a: ivy.array([2., 4., 6.]), b: ivy.array([4.75, 5.75]) } """ return ContainerBase.cont_multi_map_in_function( "imag", val, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def imag( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.imag. This method simply wraps the function, and so the docstring for ivy.imag also applies to this method with minimal changes. Parameters ---------- val Array-like input. out optional output array, for writing the result to. Returns ------- ret Returns an Container including arrays with the imaginary part of complex numbers. Examples -------- >>> x = ivy.Container(a=ivy.array(np.array([1+2j, 3+4j, 5+6j])), b=ivy.array(np.array([-2.25 + 4.75j, 3.25 + 5.75j]))) >>> x { a: ivy.array([1.+2.j, 3.+4.j, 5.+6.j]), b: ivy.array([-2.25+4.75j, 3.25+5.75j]) } >>> x.imag() { a: ivy.array([2., 4., 6.]), b: ivy.array([4.75, 5.75]) } """ return self.static_imag(self, out=out)
[docs]def static_nan_to_num( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, copy: Optional[bool] = True, nan: Optional[Union[float, int]] = 0.0, posinf: Optional[Union[float, int]] = None, neginf: Optional[Union[float, int]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.nan_to_num. This method simply wraps the function, and so the docstring for ivy.nan_to_num also applies to this method with minimal changes. Parameters ---------- x Input container with array items. copy Whether to create a copy of x (True) or to replace values in-place (False). The in-place operation only occurs if casting to an array does not require a copy. Default is True. nan Value to be used to fill NaN values. If no value is passed then NaN values will be replaced with 0.0. posinf Value to be used to fill positive infinity values. If no value is passed then positive infinity values will be replaced with a very large number. neginf Value to be used to fill negative infinity values. If no value is passed then negative infinity values will be replaced with a very small (or negative) number. out optional output container, for writing the result to. Returns ------- ret Container including arrays with replaced non-finite elements. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 3, nan]),\ b=ivy.array([1, 2, 3, inf])) >>> ivy.Container.static_nan_to_num(x, posinf=5e+100) { a: ivy.array([1., 1., 3., 0.0]) b: ivy.array([1., 2., 1., 5e+100]) } """ return ContainerBase.cont_multi_map_in_function( "nan_to_num", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, copy=copy, nan=nan, posinf=posinf, neginf=neginf, out=out, )
[docs]def nan_to_num( self: ivy.Container, /, *, copy: Optional[bool] = True, nan: Optional[Union[float, int]] = 0.0, posinf: Optional[Union[float, int]] = None, neginf: Optional[Union[float, int]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.nan_to_num. This method simply wraps the function, and so the docstring for ivy.nan_to_num also applies to this method with minimal changes. Parameters ---------- self Input container with array items. copy Whether to create a copy of x (True) or to replace values in-place (False). The in-place operation only occurs if casting to an array does not require a copy. Default is True. nan Value to be used to fill NaN values. If no value is passed then NaN values will be replaced with 0.0. posinf Value to be used to fill positive infinity values. If no value is passed then positive infinity values will be replaced with a very large number. neginf Value to be used to fill negative infinity values. If no value is passed then negative infinity values will be replaced with a very small (or negative) number. out optional output container, for writing the result to. Returns ------- ret Container including arrays with replaced non-finite elements. Examples -------- >>> a = ivy.array([1., 2, 3, ivy.nan], dtype="float64") >>> b = ivy.array([1., 2, 3, ivy.inf], dtype="float64") >>> x = ivy.Container(a=a, b=b) >>> ret = x.nan_to_num(posinf=5e+100) >>> print(ret) { a: ivy.array([1., 2., 3., 0.]), b: ivy.array([1.e+000, 2.e+000, 3.e+000, 5.e+100]) } """ return self.static_nan_to_num( self, copy=copy, nan=nan, posinf=posinf, neginf=neginf, out=out )
[docs]def static_logaddexp2( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, list, tuple], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.logaddexp2. This method simply wraps the function, and so the docstring for ivy.logaddexp2 also applies to this method with minimal changes. Parameters ---------- x1 first input container with array-like items. x2 second input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise logaddexp2 of input arrays. Examples -------- >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),\ b=ivy.array([1, 2, 3])) >>> x2 = ivy.Container(a=ivy.array([4, 5, 6]),\ b=5) >>> ivy.Container.static_logaddexp2(x1, x2) { a: ivy.array([4.169925, 5.169925, 6.169925]) b: ivy.array([5.08746284, 5.169925 , 5.32192809]) } """ return ContainerBase.cont_multi_map_in_function( "logaddexp2", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def logaddexp2( self: ivy.Container, x2: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.logaddexp2. This method simply wraps the function, and so the docstring for ivy.logaddexp2 also applies to this method with minimal changes. Parameters ---------- self first input container with array-like items. x2 second input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise logaddexp2 of input arrays. Examples -------- >>> x1 = ivy.Container(a=ivy.array([1, 2, 3]),\ b=ivy.array([1, 2, 3])) >>> x2 = ivy.Container(a=ivy.array([4, 5, 6]),\ b=5) >>> x1.logaddexp2(x2) { a: ivy.array([4.169925, 5.169925, 6.169925]) b: ivy.array([5.08746284, 5.169925 , 5.32192809]) } """ return self.static_logaddexp2(self, x2, out=out)
[docs]def static_signbit( x: Union[ivy.Array, ivy.NativeArray, ivy.Container, float, int, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.signbit. This method simply wraps the function, and so the docstring for ivy.signbit also applies to this method with minimal changes. Parameters ---------- x input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise signbit of input arrays. Examples -------- >>> x = ivy.Container(a=ivy.array([1, -2, 3]),\ b=-5) >>> ivy.Container.static_signbit(x) { a: ivy.array([False, True, False]) b: ivy.array([True]) } """ return ContainerBase.cont_multi_map_in_function( "signbit", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def signbit( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.signbit. This method simply wraps the function, and so the docstring for ivy.signbit also applies to this method with minimal changes. Parameters ---------- self input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise signbit of input arrays. Examples -------- >>> x = ivy.Container(a=ivy.array([1, -2, 3]),\ b=-5) >>> x.signbit() { a: ivy.array([False, True, False]) b: ivy.array([True]) } """ return self.static_signbit(self, out=out)
[docs]def static_allclose( x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, rtol: Optional[float] = 1e-05, atol: Optional[float] = 1e-08, equal_nan: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.allclose. This method simply wraps the function, and so the docstring for ivy.allclose also applies to this method with minimal changes. Parameters ---------- x1 Input container containing first input array. x2 Input container containing second input array. rtol The relative tolerance parameter. atol The absolute tolerance parameter. equal_nan Whether to compare NaN's as equal. If True, NaN's in x1 will be considered equal to NaN's in x2 in the output array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret A new container holding the result is returned unless out is specified, in which it is returned. Examples -------- >>> x1 = ivy.Container(a=ivy.array([1., 2., 3.]),\ ... b=ivy.array([1., 2., 3.])) >>> x2 = ivy.Container(a=ivy.array([1., 2., 3.]),\ ... b=ivy.array([1., 2., 3.])) >>> y = ivy.Container.static_allclose(x1, x2) >>> print(y) { a: ivy.array(True), b: ivy.array(True) } >>> x1 = ivy.Container(a=ivy.array([1., 2., 3.]),\ ... b=ivy.array([1., 2., 3.])) >>> x2 = ivy.Container(a=ivy.array([1., 2., 3.0003]),\ ... b=ivy.array([1.0006, 2., 3.])) >>> y = ivy.Container.static_allclose(x1, x2, rtol=1e-3) >>> print(y) { a: ivy.array(True), b: ivy.array(True) } """ return ContainerBase.cont_multi_map_in_function( "allclose", x1, x2, rtol=rtol, atol=atol, equal_nan=equal_nan, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def allclose( self: ivy.Container, x2: ivy.Container, /, *, rtol: Optional[float] = 1e-05, atol: Optional[float] = 1e-08, equal_nan: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.allclose. This method simply wraps the function, and so the docstring for ivy.allclose also applies to this method with minimal changes. Parameters ---------- self Input container containing first input array. x2 Input container containing second input array. rtol The relative tolerance parameter. atol The absolute tolerance parameter. equal_nan Whether to compare NaN's as equal. If True, NaN's in x1 will be considered equal to NaN's in x2 in the output array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret A new container holding the result is returned unless out is specified, in which it is returned. Examples -------- >>> x1 = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([1., 2., 3.])) >>> x2 = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([1., 2., 3.])) >>> y = x1.allclose(x2) >>> print(y) { a: ivy.array(True), b: ivy.array(True) } >>> x1 = ivy.Container(a=ivy.array([1., 2., 3.]),\ ... b=ivy.array([1., 2., 3.])) >>> x2 = ivy.Container(a=ivy.array([1., 2., 3.0003]),\ ... b=ivy.array([1.0006, 2., 3.])) >>> y = x1.allclose(x2, rtol=1e-3) >>> print(y) { a: ivy.array(True), b: ivy.array(True) } """ return self.static_allclose( self, x2, rtol=rtol, atol=atol, equal_nan=equal_nan, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_diff( x: Union[ivy.Array, ivy.NativeArray, ivy.Container, int, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.diff. This method simply wraps the function, and so the docstring for ivy.diff also applies to this method with minimal changes. Parameters ---------- x input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with the n-th discrete difference along the given axis. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 4, 7, 0]),\ b=ivy.array([1, 2, 4, 7, 0])) >>> ivy.Container.static_diff(x) { a: ivy.array([ 1, 2, 3, -7]) b: ivy.array([ 1, 2, 3, -7]) } """ return ContainerBase.cont_multi_map_in_function( "diff", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def diff( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.diff. This method simply wraps the function, and so the docstring for ivy.diff also applies to this method with minimal changes. Parameters ---------- self input container with array-like items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with the n-th discrete difference along the given axis. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 2, 4, 7, 0]),\ b=ivy.array([1, 2, 4, 7, 0])) >>> ivy.Container.static_diff(x) { a: ivy.array([ 1, 2, 3, -7]) b: ivy.array([ 1, 2, 3, -7]) } """ return self.static_diff(self, out=out)
[docs]def static_fix( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.fix. This method simply wraps the function, and so the docstring for ivy.fix also applies to this method with minimal changes. Parameters ---------- x input container with array items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise rounding of input arrays elements. Examples -------- >>> x = ivy.Container(a=ivy.array([2.1, 2.9, -2.1]),\ b=ivy.array([3.14])) >>> ivy.Container.static_fix(x) { a: ivy.array([ 2., 2., -2.]) b: ivy.array([ 3.0 ]) } """ return ContainerBase.cont_multi_map_in_function( "fix", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def fix( self: ivy.Container, /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.fix. This method simply wraps the function, and so the docstring for ivy.fix also applies to this method with minimal changes. Parameters ---------- self input container with array items. out optional output container, for writing the result to. Returns ------- ret Container including arrays with element-wise rounding of input arrays elements. Examples -------- >>> x = ivy.Container(a=ivy.array([2.1, 2.9, -2.1]),\ b=ivy.array([3.14])) >>> x.fix() { a: ivy.array([ 2., 2., -2.]) b: ivy.array([ 3.0 ]) } """ return self.static_fix(self, out=out)
[docs]def static_nextafter( x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.nextafter. This method simply wraps the function, and so the docstring for ivy.nextafter also applies to this method with minimal changes. Parameters ---------- x1 Input container containing first input arrays. x2 Input container containing second input arrays. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret container including the next representable values of input container's arrays, element-wise Examples -------- >>> x1 = ivy.Container(a=ivy.array([1.0e-50, 2.0e+50]),\ ... b=ivy.array([2.0, 1.0]) >>> x2 = ivy.Container(a=ivy.array([5.5e-30]),\ ... b=ivy.array([-2.0])) >>> ivy.Container.static_nextafter(x1, x2) { a: ivy.array([1.4013e-45., 3.4028e+38]), b: ivy.array([5.5e-30]) } """ return ContainerBase.cont_multi_map_in_function( "nextafter", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def nextafter( self: ivy.Container, x2: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.nextafter. This method simply wraps the function, and so the docstring for ivy.nextafter also applies to this method with minimal changes. Parameters ---------- self Input container containing first input array. x2 Input container containing second input array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret container including the next representable values of input container's arrays, element-wise Examples -------- >>> x1 = ivy.Container(a=ivy.array([1.0e-50, 2.0e+50]),\ ... b=ivy.array([2.0, 1.0]) >>> x2 = ivy.Container(a=ivy.array([5.5e-30]),\ ... b=ivy.array([-2.0])) >>> x1.nextafter(x2) { a: ivy.array([1.4013e-45., 3.4028e+38]), b: ivy.array([5.5e-30]) } """ return self.static_nextafter( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_zeta( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], q: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.zeta. This method simply wraps the function, and so the docstring for ivy.zeta also applies to this method with minimal changes. Parameters ---------- x Input container containing first input arrays. q Input container containing second input arrays. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret container including the zeta function computed element-wise Examples -------- >>> x = ivy.Container(a=ivy.array([5.0, 3.0]),\ ... b=ivy.array([2.0, 1.0]) >>> q = ivy.Container(a=ivy.array([2.0]),\ ... b=ivy.array([5.0])) >>> ivy.Container.static_zeta(x1, x2) { a: ivy.array([0.0369, 0.2021]), b: ivy.array([0.0006, 0.0244]) } """ return ContainerBase.cont_multi_map_in_function( "zeta", x, q, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def zeta( self: ivy.Container, q: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.zeta. This method simply wraps the function, and so the docstring for ivy.zeta also applies to this method with minimal changes. Parameters ---------- self Input container containing first input array. q Input container containing second input array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret container including the zeta function computed element-wise Examples -------- >>> x = ivy.Container(a=ivy.array([5.0, 3.0]),\ ... b=ivy.array([2.0, 1.0]) >>> q = ivy.Container(a=ivy.array([2.0]),\ ... b=ivy.array([5.0])) >>> x.zeta(q) { a: ivy.array([0.0369, 0.2021]), b: ivy.array([0.0006, 0.0244]) } """ return self.static_zeta( self, q, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_gradient( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, spacing: Optional[Union[int, list, tuple]] = 1, edge_order: Optional[int] = 1, axis: Optional[Union[int, list, tuple]] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "gradient", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, spacing=spacing, edge_order=edge_order, axis=axis, )
[docs]def gradient( self: ivy.Container, /, *, spacing: Optional[Union[int, list, tuple]] = 1, edge_order: Optional[int] = 1, axis: Optional[Union[int, list, tuple]] = None, ) -> ivy.Container: """Calculates gradient of x with respect to (w.r.t.) spacing Parameters ---------- x input array representing outcomes of the function spacing if not given, indices of x will be used if scalar indices of x will be scaled with this value if array gradient of x w.r.t. spacing edge_order 1 or 2, for 'frist order' and 'second order' estimation of boundary values of gradient respectively. axis dimension(s) to approximate the gradient over. By default, partial gradient is computed in every dimension Returns ------- ret Array with values computed from gradient function from inputs Examples -------- >>> coordinates = ivy.Container( >>> a=(ivy.array([-2., -1., 1., 4.]),), >>> b=(ivy.array([2., 1., -1., -4.]),) >>> ) >>> values = ivy.Container( >>> a=ivy.array([4., 1., 1., 16.]), >>> b=ivy.array([4., 1., 1., 16.]) >>> ) >>> ivy.gradient(values, spacing=coordinates) { a: ivy.array([-3., -2., 2., 5.]), b: ivy.array([3., 2., -2., -5.]) } >>> values = ivy.Container( >>> a=ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]]), >>> b=ivy.array([[-1, -2, -4, -8], [-10, -20, -40, -80]]) >>> ) >>> ivy.gradient(values) [{ a: ivy.array([[9., 18., 36., 72.], [9., 18., 36., 72.]]), b: ivy.array([[-9., -18., -36., -72.], [-9., -18., -36., -72.]]) }, { a: ivy.array([[1., 1.5, 3., 4.], [10., 15., 30., 40.]]), b: ivy.array([[-1., -1.5, -3., -4.], [-10., -15., -30., -40.]]) }] >>> values = ivy.Container( >>> a=ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]]), >>> b=ivy.array([[-1, -2, -4, -8], [-10, -20, -40, -80]]) >>> ) >>> ivy.gradient(values, spacing=2.0) [{ a: ivy.array([[4.5, 9., 18., 36.], [4.5, 9., 18., 36.]]), b: ivy.array([[-4.5, -9., -18., -36.], [-4.5, -9., -18., -36.]]) }, { a: ivy.array([[0.5, 0.75, 1.5, 2.], [5., 7.5, 15., 20.]]), b: ivy.array([[-0.5, -0.75, -1.5, -2.], [-5., -7.5, -15., -20.]]) }] >>> values = ivy.Container( >>> a=ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]]), >>> b=ivy.array([[-1, -2, -4, -8], [-10, -20, -40, -80]]) >>> ) >>> ivy.gradient(values, axis=1) { a: ivy.array([[1., 1.5, 3., 4.], [10., 15., 30., 40.]]), b: ivy.array([[-1., -1.5, -3., -4.], [-10., -15., -30., -40.]]) } >>> values = ivy.Container( >>> a=ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]]), >>> b=ivy.array([[-1, -2, -4, -8], [-10, -20, -40, -80]]) >>> ) >>> ivy.gradient(values, spacing = [3., 2.]) [{ a: ivy.array([[3., 6., 12., 24.], [3., 6., 12., 24.]]), b: ivy.array([[-3., -6., -12., -24.], [-3., -6., -12., -24.]]) }, { a: ivy.array([[0.5, 0.75, 1.5, 2.], [5., 7.5, 15., 20.]]), b: ivy.array([[-0.5, -0.75, -1.5, -2.], [-5., -7.5, -15., -20.]]) }] >>> coords = ivy.Container( >>> a=(ivy.array([0, 2]), ivy.array([0, 3, 6, 9])), >>> b=(ivy.array([0, -2]), ivy.array([0, -3, -6, -9])) >>>) >>> values = ivy.Container( >>> a=ivy.array([[1, 2, 4, 8], [10, 20, 40, 80]]), >>> b=ivy.array([[-1, -2, -4, -8], [-10, -20, -40, -80]]) >>>) >>> ivy.gradient(values, spacing = coords) [{ a: ivy.array([[4.5, 9., 18., 36.], [4.5, 9., 18., 36.]]), b: ivy.array([[4.5, 9., 18., 36.], [4.5, 9., 18., 36.]]) }, { a: ivy.array([[0.33333333, 0.5, 1., 1.33333333], [3.33333333, 5., 10., 13.33333333]]), b: ivy.array([[0.33333333, 0.5, 1., 1.33333333], [3.33333333, 5., 10., 13.33333333]]) }] """ return self.static_gradient( self, spacing=spacing, edge_order=edge_order, axis=axis )
[docs]def static_xlogy( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], y: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Array] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.xlogy. This method simply wraps the function, and so the docstring for ivy.xlogy also applies to this method with minimal changes. Parameters ---------- x Input container containing first input arrays. y Input container containing second input arrays. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret container including the next representable values of input container's arrays, element-wise Examples -------- >>> x = ivy.Container(a=ivy.zeros(3)),\ ... b=ivy.array([1.0, 2.0, 3.0])) >>> y = ivy.Container(a=ivy.array([-1.0, 0.0, 1.0]),\ ... b=ivy.array([3.0, 2.0, 1.0])) >>> ivy.Container.static_xlogy(x, y) { a: ivy.array([0.0, 0.0, 0.0]), b: ivy.array([1.0986, 1.3863, 0.0000]) } """ return ContainerBase.cont_multi_map_in_function( "xlogy", x, y, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def xlogy( self: ivy.Container, y: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.xlogy. This method simply wraps the function, and so the docstring for ivy.xlogy also applies to this method with minimal changes. Parameters ---------- self Input container containing first input array. y Input container containing second input array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out Alternate output array in which to place the result. The default is None. Returns ------- ret container including the next representable values of input container's arrays, element-wise Examples -------- >>> x = ivy.Container(a=ivy.zeros(3)),\ ... b=ivy.array([1.0, 2.0, 3.0])) >>> y = ivy.Container(a=ivy.array([-1.0, 0.0, 1.0]),\ ... b=ivy.array([3.0, 2.0, 1.0])) >>> x.xlogy(y) { a: ivy.array([0.0, 0.0, 0.0]), b: ivy.array([1.0986, 1.3863, 0.0000]) } """ return self.static_xlogy( self, y, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_real( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.real. This method simply wraps the function, and so the docstring for ivy.real also applies to this method with minimal changes. Parameters ---------- x input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``out_i`` if ``x_i`` is real number part only else ``real number part``, if it contains real and complex part both. The returned array should have a data type of ``float``. Examples -------- >>> x = ivy.Container(a=ivy.array([-1+5j, 0-0j, 1.23j]), ... b=ivy.array([7.9, 0.31+3.3j, -4.2-5.9j])) >>> z = ivy.Container.static_real(x) >>> print(z) { a: ivy.array([-1., 0., 0.]), b: ivy.array([7.9, 0.31, -4.2]) } """ return ContainerBase.cont_multi_map_in_function( "real", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def real( self: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.real. This method simply wraps the function, and so the docstring for ivy.real also applies to this method with minimal changes. Parameters ---------- self input container. Should have a real-valued floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the test result. An element ``out_i`` is ``self_i`` if ``self_i`` is real number else ``took real number part only`` if ``self_i`` contains real number and complex number both. The returned array should have a data type of ``float``. Examples -------- >>> x = ivy.Container(a=ivy.array([-1j, 0.335+2.345j, 1.23+7j]),\ b=ivy.array([0.0, 1.2+3.3j, 1+0j])) >>> x.real() { a: ivy.array([0., 0.335, 1.23]), b: ivy.array([0.0, 1.2, 1.]) } """ return self.static_real( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_dirichlet( alpha: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, size: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.dirichlet. This method simply wraps the function, and so the docstring for ivy.dirichlet also applies to this method with minimal changes. Parameters ---------- alpha Sequence of floats of length k size optional container including ints or tuple of ints, Output shape for the arrays in the input container. dtype output container array data type. If ``dtype`` is ``None``, the output data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output container, for writing the result to. Returns ------- ret container including the drawn samples. Examples -------- >>> alpha = ivy.Container(a=ivy.array([7,6,5]), \ b=ivy.array([8,9,4])) >>> size = ivy.Container(a=3, b=5) >>> ivy.Container.static_dirichlet(alpha, size) { a: ivy.array( [[0.43643127, 0.32325703, 0.24031169], [0.34251311, 0.31692529, 0.3405616 ], [0.5319725 , 0.22458365, 0.24344385]] ), b: ivy.array( [[0.26588406, 0.61075421, 0.12336174], [0.51142915, 0.25041268, 0.23815817], [0.64042903, 0.25763214, 0.10193883], [0.31624692, 0.46567987, 0.21807321], [0.37677699, 0.39914594, 0.22407707]] ) } """ return ContainerBase.cont_multi_map_in_function( "dirichlet", alpha, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, size=size, dtype=dtype, out=out, )
[docs]def dirichlet( self: ivy.Container, /, *, size: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.dirichlet. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes. Parameters ---------- self Sequence of floats of length k size optional container including ints or tuple of ints, Output shape for the arrays in the input container. dtype output container array data type. If ``dtype`` is ``None``, the output data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output container, for writing the result to. Returns ------- ret container including the drawn samples. Examples -------- >>> alpha = ivy.Container(a=ivy.array([7,6,5]), \ b=ivy.array([8,9,4])) >>> size = ivy.Container(a=3, b=5) >>> alpha.dirichlet(size) { a: ivy.array( [[0.43643127, 0.32325703, 0.24031169], [0.34251311, 0.31692529, 0.3405616 ], [0.5319725 , 0.22458365, 0.24344385]] ), b: ivy.array( [[0.26588406, 0.61075421, 0.12336174], [0.51142915, 0.25041268, 0.23815817], [0.64042903, 0.25763214, 0.10193883], [0.31624692, 0.46567987, 0.21807321], [0.37677699, 0.39914594, 0.22407707]] ) } """ return self.static_dirichlet( self, size=size, dtype=dtype, out=out, )
[docs]def static_beta( alpha: Union[int, float, ivy.Container, ivy.Array, ivy.NativeArray], beta: Union[int, float, ivy.Container, ivy.Array, ivy.NativeArray], /, *, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[str] = None, dtype: Optional[str] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.beta. This method simply wraps the function, and so the docstring for ivy.beta also applies to this method with minimal changes. Parameters ---------- x Input array or container. Should have a numeric data type. alpha The alpha parameter of the distribution. beta The beta parameter of the distribution. shape The shape of the output array. Default is ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device The device to place the output array on. Default is ``None``. dtype The data type of the output array. Default is ``None``. seed A python integer. Used to create a random seed distribution out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container object, with values drawn from the beta distribution. """ return ContainerBase.cont_multi_map_in_function( "beta", alpha, beta, shape=shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, device=device, dtype=dtype, seed=seed, out=out, )
[docs]def beta( self: ivy.Container, /, *, alpha: Union[int, float, ivy.Container, ivy.Array, ivy.NativeArray], beta: Union[int, float, ivy.Container, ivy.Array, ivy.NativeArray], shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[str] = None, dtype: Optional[str] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.beta. This method simply wraps the function, and so the docstring for ivy.beta also applies to this method with minimal changes. Parameters ---------- self Input container. Should have a numeric data type. alpha The alpha parameter of the distribution. beta The beta parameter of the distribution. shape The shape of the output array. Default is ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device The device to place the output array on. Default is ``None``. dtype The data type of the output array. Default is ``None``. seed A python integer. Used to create a random seed distribution out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container object, with values drawn from the beta distribution. """ return self.static_beta( self, alpha, beta, shape=shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, device=device, dtype=dtype, seed=seed, out=out, )
[docs]def static_poisson( lam: ivy.Container, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.poisson. This method simply wraps the function, and so the docstring for ivy.poisson also applies to this method with minimal changes. Parameters ---------- lam Input container with rate parameter(s) describing the poisson distribution(s) to sample. shape optional container including ints or tuple of ints, Output shape for the arrays in the input container. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output container array data type. If ``dtype`` is ``None``, the output data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output container, for writing the result to. Returns ------- ret container including the drawn samples. Examples -------- >>> lam = ivy.Container(a=ivy.array([7,6,5]), \ b=ivy.array([8,9,4])) >>> shape = ivy.Container(a=(2,3), b=(1,1,3)) >>> ivy.Container.static_poisson(lam, shape=shape) { a: ivy.array([[5, 4, 6], [12, 4, 5]]), b: ivy.array([[[8, 13, 3]]]) } """ return ContainerBase.cont_multi_map_in_function( "poisson", lam, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, shape=shape, device=device, dtype=dtype, out=out, )
[docs]def poisson( self: ivy.Container, /, *, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.poisson. This method simply wraps the function, and so the docstring for ivy.poisson also applies to this method with minimal changes. Parameters ---------- self Input container with rate parameter(s) describing the poisson distribution(s) to sample. shape optional container including ints or tuple of ints, Output shape for the arrays in the input container. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output container array data type. If ``dtype`` is ``None``, the output data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output container, for writing the result to. Returns ------- ret container including the drawn samples. Examples -------- >>> lam = ivy.Container(a=ivy.array([7,6,5]), \ b=ivy.array([8,9,4])) >>> shape = ivy.Container(a=(2,3), b=(1,1,3)) >>> lam.poisson(shape=shape) { a: ivy.array([[5, 4, 6], [12, 4, 5]]), b: ivy.array([[[8, 13, 3]]]) } """ return self.static_poisson( self, shape=shape, device=device, dtype=dtype, seed=seed, out=out, )
[docs]def static_isin( element: ivy.Container, test_elements: ivy.Container, /, *, assume_unique: Optional[bool] = False, invert: Optional[bool] = False, ) -> ContainerBase: """Container instance method variant of ivy.isin. This method simply wraps the function, and so the docstring for ivy.isin also applies to this method with minimal changes. Parameters ---------- element input container test_elements values against which to test for each input element assume_unique If True, assumes both elements and test_elements contain unique elements, which can speed up the calculation. Default value is False. invert If True, inverts the boolean return array, resulting in True values for elements not in test_elements. Default value is False. Returns ------- ret output a boolean container of the same shape as elements that is True for elements in test_elements and False otherwise. Examples -------- >>> x = ivy.Container(a=[[10, 7, 4], [3, 2, 1]],\ b=[3, 2, 1, 0]) >>> y = ivy.Container(a=[1, 2, 3],\ b=[1, 0, 3]) >>> ivy.Container.static_isin(x, y) ivy.Container(a=[[False, False, False], [ True, True, True]],\ b=[ True, False, True]) >>> ivy.Container.static_isin(x, y, invert=True) ivy.Container(a=[[ True, True, True], [False, False, False]],\ b=[False, True, False]) """ return ContainerBase.cont_multi_map_in_function( "isin", element, test_elements, assume_unique=assume_unique, invert=invert )
[docs]def isin( self: ivy.Container, test_elements: ivy.Container, /, *, assume_unique: Optional[bool] = False, invert: Optional[bool] = False, ) -> ivy.Container: """Container instance method variant of ivy.isin. This method simply wraps the function, and so the docstring for ivy.isin also applies to this method with minimal changes. Parameters ---------- self input array test_elements values against which to test for each input element assume_unique If True, assumes both elements and test_elements contain unique elements, which can speed up the calculation. Default value is False. invert If True, inverts the boolean return array, resulting in True values for elements not in test_elements. Default value is False. Returns ------- ret output a boolean array of the same shape as elements that is True for elements in test_elements and False otherwise. Examples -------- >>> x = ivy.Container(a=[[10, 7, 4], [3, 2, 1]],\ b=[3, 2, 1, 0]) >>> y = ivy.Container(a=[1, 2, 3],\ b=[1, 0, 3]) >>> x.isin(y) ivy.Container(a=[[False, False, False], [ True, True, True]],\ b=[ True, False, True]) """ return self.static_isin( self, test_elements, assume_unique=assume_unique, invert=invert )
[docs]def static_msort( a: Union[ivy.Array, ivy.NativeArray, ivy.Container, list, tuple], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.msort. This method simply wraps the function, and so the docstring for ivy.msort also applies to this method with minimal changes. Parameters ---------- a array-like or container input. out optional output container, for writing the result to. Returns ------- ret a container containing sorted input arrays. Examples -------- With :class:`ivy.Container` input: >>> a = ivy.Container(x = ivy.randint(10, size=(2,3)), ... y = ivy.randint(5, size=(2,2)) >>> ivy.Container.static_msort(a) { x: ivy.array( [[6, 2, 6], [8, 9, 6]] ), y: ivy.array( [[0, 0], [4, 0]] ) } """ return ContainerBase.cont_multi_map_in_function( "msort", a, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def msort( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.msort. This method simply wraps the function, and so the docstring for ivy.msort also applies to this method with minimal changes. Parameters ---------- self input container with array-like inputs to sort. out optional output container, for writing the result to. Returns ------- ret a container containing the sorted input arrays. Examples -------- >>> a = ivy.Container(x = ivy.randint(10, size=(2,3)), ... y = ivy.randint(5, size=(2,2)) >>> a.msort() { x: ivy.array( [[6, 2, 6], [8, 9, 6]] ), y: ivy.array( [[0, 0], [4, 0]] ) } """ return self.static_msort( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.general # global from numbers import Number from typing import Any, Union, List, Dict, Iterable, Optional, Callable # local from ivy.container.base import ContainerBase import ivy # ToDo: implement all methods here as public instance methods # noinspection PyMissingConstructor
[docs]def static_is_native_array( x: ivy.Container, /, *, exclusive: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.is_native_array. This method simply wraps the function, and so the docstring for ivy.is_native_array also applies to this method with minimal changes. Parameters ---------- x The input to check exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean, whether or not x is a native array. Examples -------- >>> x = ivy.Container(a=ivy.array([1]), b=ivy.native_array([2, 3])) >>> y = ivy.Container.static_is_native_array(x) >>> print(y) { a: false, b: true } """ return ContainerBase.cont_multi_map_in_function( "is_native_array", x, exclusive=exclusive, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_native_array( self: ivy.Container, /, *, exclusive: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.is_native_array. This method simply wraps the function, and so the docstring for ivy.ivy.is_native_array also applies to this method with minimal changes. Parameters ---------- self The input to check exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean, whether or not x is a native array. Examples -------- >>> x = ivy.Container(a=ivy.array([1]), b=ivy.native_array([2, 3])) >>> y = x.is_native_array() >>> print(y) { a: false, b: true } """ return self.static_is_native_array( self, exclusive=exclusive, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_is_ivy_array( x: ivy.Container, /, *, exclusive: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.is_ivy_array. This method simply wraps the function, and so the docstring for ivy.is_ivy_array also applies to this method with minimal changes. Parameters ---------- x The input to check exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean, whether or not x is an array. >>> x = ivy.Container(a=ivy.array([1]), b=ivy.native_array([2, 3])) >>> y = ivy.Container.static_is_ivy_array(x) >>> print(y) { a: true, b: false } """ return ContainerBase.cont_multi_map_in_function( "is_ivy_array", x, exclusive=exclusive, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_ivy_array( self: ivy.Container, /, *, exclusive: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.is_native_array. This method simply wraps the function, and so the docstring for ivy.ivy.is_native_array also applies to this method with minimal changes. Parameters ---------- self The input to check exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean, whether or not x is an array. >>> x = ivy.Container(a=ivy.array([1]), b=ivy.native_array([2, 3])) >>> y = x.is_ivy_array() >>> print(y) { a: true, b: false } """ return self.static_is_ivy_array( self, exclusive=exclusive, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_is_array( x: ivy.Container, /, *, exclusive: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.is_array. This method simply wraps the function, and so the docstring for ivy.ivy.is_array also applies to this method with minimal changes. Parameters ---------- x The input to check exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Boolean, whether or not x is an array. Examples -------- >>> x = ivy.Container(a=ivy.array([1]), b=ivy.native_array([2, 3])) >>> y = ivy.Container.static_is_array(x) >>> print(y) { a: true, b: true } """ return ContainerBase.cont_multi_map_in_function( "is_array", x, exclusive=exclusive, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def is_array( self: ivy.Container, /, *, exclusive: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.is_array. This method simply wraps the function, and so the docstring for ivy.is_array also applies to this method with minimal changes. Parameters ---------- self The input to check exclusive Whether to check if the data type is exclusively an array, rather than a variable or traced array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean, whether or not x is an array. Examples -------- >>> x = ivy.Container(a=ivy.array([1]), b=ivy.native_array([2, 3])) >>> y = x.is_array() >>> print(y) { a: true, b: true } """ return self.static_is_array( self, exclusive=exclusive, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_clip_vector_norm( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], max_norm: float, /, *, p: float = 2.0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.clip_vector_norm. This method simply wraps the function, and so the docstring for ivy.clip_vector_norm also applies to this method with minimal changes. Parameters ---------- x input array max_norm float, the maximum value of the array norm. p optional float, the p-value for computing the p-norm. Default is 2. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret An array with the vector norm downscaled to the max norm if needed. Examples -------- With :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]),b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_clip_vector_norm(x, 2.0) >>> print(y) { a: ivy.array([0., 0.894, 1.79]), b: ivy.array([0.849, 1.13, 1.41]) } """ return ContainerBase.cont_multi_map_in_function( "clip_vector_norm", x, max_norm, p=p, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def clip_vector_norm( self: ivy.Container, max_norm: float, /, *, p: float = 2.0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.clip_vector_norm. This method simply wraps the function, and so the docstring for ivy.clip_vector_norm also applies to this method with minimal changes. Parameters ---------- self input array max_norm float, the maximum value of the array norm. p optional float, the p-value for computing the p-norm. Default is 2. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret An array with the vector norm downscaled to the max norm if needed. Examples -------- With :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> y = x.clip_vector_norm(2.0, p=1.0) >>> print(y) { a: ivy.array([0., 0.667, 1.33]), b: ivy.array([0.5, 0.667, 0.833]) } """ return self.static_clip_vector_norm( self, max_norm, p=p, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_inplace_update( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], val: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.inplace_update. This method simply wraps the function, and so the docstring for ivy.inplace_update also applies to this method with minimal changes. Parameters ---------- x input container to be updated inplace val value to update the input container with key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret An array with the vector norm downscaled to the max norm if needed. """ # inplace update the leaves cont = x cont = ContainerBase.cont_multi_map_in_function( "inplace_update", cont, val, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, ) # inplace update the container x.cont_inplace_update(cont) return x
[docs]def inplace_update( self: ivy.Container, val: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.inplace_update. This method simply wraps the function, and so the docstring for ivy.inplace_update also applies to this method with minimal changes. Parameters ---------- self input container to be updated inplace val value to update the input container with key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret An array with the vector norm downscaled to the max norm if needed. """ return self.static_inplace_update( self, val, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_inplace_decrement( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], val: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.inplace_decrement. This method simply wraps the function, and so the docstring for ivy.inplace_decrement also applies to this method with minimal changes. Parameters ---------- x The input array to be decremented by the defined value. val The value of decrement. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret The array following an in-place decrement. Examples -------- Decrement by a value >>> x = ivy.Container(a=ivy.array([0.5, -5., 30.]),b=ivy.array([0., -25., 50.])) >>> y = ivy.inplace_decrement(x, 1.5) >>> print(y) { a: ivy.array([-1., -6.5, 28.5]), b: ivy.array([-1.5, -26.5, 48.5]) } Decrement by a Container >>> x = ivy.Container(a=ivy.array([0., 15., 30.]), b=ivy.array([0., 25., 50.])) >>> y = ivy.Container(a=ivy.array([0., 15., 30.]), b=ivy.array([0., 25., 50.])) >>> z = ivy.inplace_decrement(x, y) >>> print(z) { a: ivy.array([0., 0., 0.]), b: ivy.array([0., 0., 0.]) } >>> x = ivy.Container(a=ivy.array([3., 7., 10.]), b=ivy.array([0., 75., 5.5])) >>> y = ivy.Container(a=ivy.array([2., 5.5, 7.]), b=ivy.array([0., 25., 2.])) >>> z = ivy.inplace_decrement(x, y) >>> print(z) { a: ivy.array([1., 1.5, 3.]), b: ivy.array([0., 50., 3.5]) } """ return ContainerBase.cont_multi_map_in_function( "inplace_decrement", x, val, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def inplace_decrement( self: ivy.Container, val: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.inplace_decrement. This method simply wraps the function, and so the docstring for ivy.inplace_decrement also applies to this method with minimal changes. Parameters ---------- self Input container to apply an in-place decrement. val The value of decrement. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A container with the array following the in-place decrement. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([-6.7, 2.4, -8.5]), ... b=ivy.array([1.5, -0.3, 0]), ... c=ivy.array([-4.7, -5.4, 7.5])) >>> y = x.inplace_decrement(2) >>> print(y) { a: ivy.array([-8.7, 0.4, -10.5]), b: ivy.array([-0.5, -2.3, -2]), c: ivy.array([-6.7, -7.4, 5.5]) } """ return self.static_inplace_decrement( self, val, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_inplace_increment( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], val: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.inplace_increment. This method simply wraps the function, and so the docstring for ivy.inplace_increment also applies to this method with minimal changes. Parameters ---------- x The input array to be incremented by the defined value. val The value of increment. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret The array following an in-place increment. Examples -------- Increment by a value >>> x = ivy.Container(a=ivy.array([0.5, -5., 30.]),b=ivy.array([0., -25., 50.])) >>> y = ivy.inplace_increment(x, 1.5) >>> print(y) { a: ivy.array([2., -3.5, 31.5]), b: ivy.array([1.5, -23.5, 51.5]) } Increment by a Container >>> x = ivy.Container(a=ivy.array([0., 15., 30.]), b=ivy.array([0., 25., 50.])) >>> y = ivy.Container(a=ivy.array([0., 15., 30.]), b=ivy.array([0., 25., 50.])) >>> z = ivy.inplace_increment(x, y) >>> print(z) { a: ivy.array([0., 30., 60.]), b: ivy.array([0., 50., 100.]) } >>> x = ivy.Container(a=ivy.array([3., 7., 10.]), b=ivy.array([0., 75., 5.5])) >>> y = ivy.Container(a=ivy.array([2., 5.5, 7.]), b=ivy.array([0., 25., 2.])) >>> z = ivy.inplace_increment(x, y) >>> print(z) { a: ivy.array([5., 12.5, 17.]), b: ivy.array([0., 100., 7.5]) } """ return ContainerBase.cont_multi_map_in_function( "inplace_increment", x, val, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def inplace_increment( self: ivy.Container, val: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.inplace_increment. This method wraps the function, and so the docstring for ivy.inplace_increment also applies to this method with minimal changes. Parameters ---------- self Input container to apply an in-place increment. val The value of increment. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A container with the array following the in-place increment. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([-6.7, 2.4, -8.5]), ... b=ivy.array([1.5, -0.3, 0]), ... c=ivy.array([-4.7, -5.4, 7.5])) >>> y = x.inplace_increment(2) >>> print(y) { a: ivy.array([-4.7, 4.4, -6.5]), b: ivy.array([3.5, 1.7, 2.]), c: ivy.array([-2.7, -3.4, 9.5]) } """ return self.static_inplace_increment( self, val, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_assert_supports_inplace( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.assert_supports_inplace. This method simply wraps the function, and so the docstring for ivy.assert_supports_inplace also applies to this method with minimal changes. Parameters ---------- x input container to check for inplace support for. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret True if support, raises exception otherwise` """ return ContainerBase.cont_multi_map_in_function( "assert_supports_inplace", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def assert_supports_inplace( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.assert_supports_inplace. This method simply wraps the function, and so the docstring for ivy.assert_supports_inplace also applies to this method with minimal changes. Parameters ---------- x input container to check for inplace support for. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a container of whether or not inplace operations are supported for x and its leaves. """ return self.static_assert_supports_inplace( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_all_equal( x1: ivy.Container, *xs: Iterable[Any], equality_matrix: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.all_equal. This method simply wraps the function, and so the docstring for ivy.all_equal also applies to this method with minimal changes. Parameters ---------- x1 input container. xs arrays or containers to be compared to ``x1``. equality_matrix Whether to return a matrix of equalities comparing each input with every other. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean, whether or not the inputs are equal, or matrix container of booleans if equality_matrix=True is set. Examples -------- With one :class:`ivy.Container` input: >>> x1 = ivy.Container(a=ivy.array([1, 0, 1, 1]), b=ivy.array([1, -1, 0, 0])) >>> x2 = ivy.array([1, 0, 1, 1]) >>> y = ivy.Container.static_all_equal(x1, x2, equality_matrix= False) >>> print(y) { a: ivy.array([True, True, True, True]), b: ivy.array([True, False, False, False]) } With multiple :class:`ivy.Container` input: >>> x1 = ivy.Container(a=ivy.array([1, 0, 1, 1]), ... b=ivy.native_array([1, 0, 0, 1])) >>> x2 = ivy.Container(a=ivy.native_array([1, 0, 1, 1]), ... b=ivy.array([1, 0, -1, -1])) >>> y = ivy.Container.static_all_equal(x1, x2, equality_matrix= False) >>> print(y) { a: ivy.array([True, True, True, True]), b: ivy.array([True, True, False, False]) } """ return ContainerBase.cont_multi_map_in_function( "all_equal", x1, *xs, equality_matrix=equality_matrix, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def all_equal( self: ivy.Container, *xs: Iterable[Any], equality_matrix: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.all_equal. This method simply wraps the function, and so the docstring for ivy.all_equal also applies to this method with minimal changes. Parameters ---------- self input container. xs arrays or containers to be compared to ``self``. equality_matrix Whether to return a matrix of equalities comparing each input with every other. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean, whether or not the inputs are equal, or matrix container of booleans if equality_matrix=True is set. Examples -------- With one :class:`ivy.Container` instances: >>> x1 = ivy.Container(a=ivy.array([1, 0, 1, 1]), b=ivy.array([1, -1, 0, 0])) >>> x2 = ivy.array([1, 0, 1, 1]) >>> y = x1.all_equal(x2, equality_matrix= False) >>> print(y) { a: true, b: false } >>> x1 = ivy.Container(a=ivy.array([1, 0, 1, 1]), b=ivy.array([1, -1, 0, 0])) >>> x2 = ivy.array([1, 0, 1, 1]) >>> y = x1.all_equal(x2, equality_matrix= False) >>> print(y) { a: true, b: false } With multiple :class:`ivy.Container` instances: >>> x1 = ivy.Container(a=ivy.native_array([1, 0, 0]), ... b=ivy.array([1, 2, 3])) >>> x2 = ivy.Container(a=ivy.native_array([1, 0, 1]), ... b=ivy.array([1, 2, 3])) >>> y = x1.all_equal(x2, equality_matrix= False) >>> print(y) { a: false, b: true } >>> x1 = ivy.Container(a=ivy.native_array([1, 0, 0]), ... b=ivy.array([1, 2, 3])) >>> x2 = ivy.Container(a=ivy.native_array([1, 0, 1]), ... b=ivy.array([1, 2, 3])) >>> y = x1.all_equal(x2, equality_matrix= False) >>> print(y) { a: false, b: true } """ return self.static_all_equal( self, *xs, equality_matrix=equality_matrix, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_fourier_encode( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], max_freq: Union[float, ivy.Array, ivy.NativeArray], /, *, num_bands: int = 4, linear: bool = False, flatten: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.fourier_encode. This method simply wraps the function, and so the docstring for ivy.fourier_encode also applies to this method with minimal changes. Parameters ---------- x Input container to apply fourier_encode. max_freq The maximum frequency of the encoding. num_bands The number of frequency bands for the encoding. Default is 4. linear Whether to space the frequency bands linearly as opposed to geometrically. Default is ``False``. flatten Whether to flatten the position dimension into the batch dimension. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret New container with the final dimension expanded of arrays at its leaves, and the encodings stored in this channel. Examples -------- >>> x = ivy.Container(a = ivy.array([1,2]), ... b = ivy.array([3,4])) >>> y = 1.5 >>> z = ivy.Container.static_fourier_encode(x, y) >>> print(z) { a: (<classivy.array.array.Array>shape=[2,9]), b: (<classivy.array.array.Array>shape=[2,9]) } >>> x = ivy.Container(a = ivy.array([3,10]), ... b = ivy.array([4,8])) >>> y = 2.5 >>> z = ivy.Container.static_fourier_encode(x, y, num_bands=3) >>> print(z) { a: ivy.array([[ 3.0000000e+00, 3.6739404e-16, 3.6739404e-16, 3.6739404e-16, -1.0000000e+00, -1.0000000e+00, -1.0000000e+00], [ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]]), b: ivy.array([[ 4.00000000e+00, -4.89858720e-16, -4.89858720e-16, -4.89858720e-16, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00], [ 8.00000000e+00, -9.79717439e-16, -9.79717439e-16, -9.79717439e-16, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]) } """ return ContainerBase.cont_multi_map_in_function( "fourier_encode", x, max_freq, num_bands=num_bands, linear=linear, concat=True, flatten=flatten, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def fourier_encode( self: ivy.Container, max_freq: Union[float, ivy.Array, ivy.NativeArray], /, *, num_bands: int = 4, linear: bool = False, flatten: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.fourier_encode. This method simply wraps the function, and so the docstring for ivy.fourier_encode also applies to this method with minimal changes. Parameters ---------- self Input container to apply fourier_encode at leaves. max_freq The maximum frequency of the encoding. num_bands The number of frequency bands for the encoding. Default is 4. linear Whether to space the frequency bands linearly as opposed to geometrically. Default is ``False``. flatten Whether to flatten the position dimension into the batch dimension. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype Data type of the returned array. Default is ``None``. out Optional output container. Default is ``None``. Returns ------- ret New container with the final dimension expanded of arrays at its leaves, and the encodings stored in this channel. Examples -------- >>> x = ivy.Container(a = ivy.array([1,2]), ... b = ivy.array([3,4])) >>> y = 1.5 >>> z = x.fourier_encode(y) >>> print(z) { a: (<classivy.array.array.Array>shape=[2,9]), b: (<classivy.array.array.Array>shape=[2,9]) } >>> x = ivy.Container(a = ivy.array([3,10]), ... b = ivy.array([4,8])) >>> y = 2.5 >>> z = x.fourier_encode(y,num_bands=3) >>> print(z) { a: ivy.array([[ 3.0000000e+00, 3.6739404e-16, 3.6739404e-16, 3.6739404e-16,-1.0000000e+00, -1.0000000e+00, -1.0000000e+00], [ 1.0000000e+01, -1.2246468e-15, -1.2246468e-15, -1.2246468e-15, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]]), b: ivy.array([[4.00000000e+00, -4.89858720e-16, -4.89858720e-16, -4.89858720e-16, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00], [ 8.00000000e+00, -9.79717439e-16, -9.79717439e-16, -9.79717439e-16, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]) } """ return self.static_fourier_encode( self, max_freq, num_bands=num_bands, linear=linear, flatten=flatten, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_gather( params: Union[ivy.Container, ivy.Array, ivy.NativeArray], indices: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Optional[int] = -1, batch_dims: Optional[int] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.gather. This method simply wraps the function, and so the docstring for ivy.gather also applies to this method with minimal changes. Parameters ---------- self The container from which to gather values. indices The container or array which indicates the indices that will be gathered along the specified axis. axis The axis from which the indices will be gathered. Default is ``-1``. batch_dims optional int, lets you gather different items from each element of a batch. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret New container with the values gathered at the specified indices along the specified axis. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a = ivy.array([0., 1., 2.]), ... b = ivy.array([4., 5., 6.])) >>> y = ivy.Container(a = ivy.array([0, 1]), ... b = ivy.array([1, 2])) >>> print(ivy.Container.static_gather(x, y)) { a: ivy.array([0., 1.]), b: ivy.array([5., 6.]) } With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs: >>> x = ivy.Container(a = ivy.array([0., 1., 2.]), ... b = ivy.array([4., 5., 6.])) >>> y = ivy.array([0, 1]) >>> print(ivy.Container.static_gather(x, y)) { a: ivy.array([0., 1.]), b: ivy.array([4., 5.]) } """ return ContainerBase.cont_multi_map_in_function( "gather", params, indices, axis=axis, batch_dims=batch_dims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def gather( self: ivy.Container, indices: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Optional[int] = -1, batch_dims: Optional[int] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.gather. This method simply wraps the function, and so the docstring for ivy.gather also applies to this method with minimal changes. Parameters ---------- self The container from which to gather values. indices The container or array which indicates the indices that will be gathered along the specified axis. axis The axis from which the indices will be gathered. Default is ``-1``. batch_dims optional int, lets you gather different items from each element of a batch. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. out optional array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret New container with the values gathered at the specified indices along the specified axis. Examples -------- >>> x = ivy.Container(a = ivy.array([0., 1., 2.]), ... b = ivy.array([4., 5., 6.])) >>> y = ivy.Container(a = ivy.array([0, 1]), ... b = ivy.array([1, 2])) >>> print(x.gather(y)) { a: ivy.array([0., 1.]), b: ivy.array([5., 6.]) } """ return self.static_gather( self, indices, axis=axis, batch_dims=batch_dims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_has_nans( self: ivy.Container, /, *, include_infs=True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ Determine whether arrays in the container contain any nans, as well as infs or -infs if specified. Parameters ---------- x The container to check for nans. include_infs Whether to include infs and -infs in the check. Default is True. Returns ------- Whether the container has any nans, applied either leafwise or across the entire container. Examples -------- >>> x = ivy.container(a=ivy.array([1, 2]), b=ivy.array([float('nan'), 2])) >>> y = ivy.Container.static_has_nans(x) >>> print(y) { a: false, b: true } """ return ContainerBase.cont_multi_map_in_function( "has_nans", self, include_infs=include_infs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def has_nans( self: ivy.Container, /, *, include_infs=True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ Determine whether arrays in the container contain any nans, as well as infs or -infs if specified. Parameters ---------- include_infs Whether to include infs and -infs in the check. Default is True. Returns ------- Whether the container has any nans, applied across the entire container. Examples -------- >>> x = ivy.container(a=ivy.array([1, 2]), b=ivy.array([float('nan'), 2])) >>> y = x.has_nans(x) >>> print(y) { a: false, b: true } """ return self.static_has_nans( self, include_infs=include_infs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_scatter_nd( indices: Union[ivy.Array, ivy.NativeArray, ivy.Container], updates: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, shape: Union[ivy.Array, ivy.NativeArray, ivy.Container] = None, *, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.scatter_nd. This method simply wraps the function, and so the docstring for ivy.scatter_nd also applies to this method with minimal changes. Parameters ---------- indices Index array or container. updates values to update input tensor with shape The shape of the result. Default is ``None``, in which case tensor argument must be provided. reduction The reduction method for the scatter, one of 'sum', 'min', 'max' or 'replace' key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ref New container of given shape, with the values updated at the indices. Examples -------- scatter into an empty array >>> indices = ivy.Container(a=ivy.array([[5],[6],[7]]), ... b=ivy.array([[2],[3],[4]])) >>> updates = ivy.Container(a=ivy.array([50, 60, 70]), ... b=ivy.array([20, 30, 40])) >>> shape = ivy.Container(a=ivy.array([10]), ... b=ivy.array([10])) >>> z = ivy.Container.static_scatter_nd(indices, updates, shape=shape) >>> print(z) { a: ivy.array([0, 0, 0, 0, 0, 50, 60, 70, 0, 0]), b: ivy.array([0, 0, 20, 30, 40, 0, 0, 0, 0, 0]) } scatter into a container >>> indices = ivy.Container(a=ivy.array([[5],[6],[7]]), ... b=ivy.array([[2],[3],[4]])) >>> updates = ivy.Container(a=ivy.array([50, 60, 70]), ... b=ivy.array([20, 30, 40])) >>> z = ivy.Container(a=ivy.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) >>> ivy.Container.static_scatter_nd(indices, updates, ... reduction='replace', out = z) >>> print(z) { a: ivy.array([1, 2, 3, 4, 5, 50, 60, 70, 9, 10]), b: ivy.array([1, 2, 20, 30, 40, 6, 7, 8, 9, 10]) } """ return ContainerBase.cont_multi_map_in_function( "scatter_nd", indices, updates, shape=shape, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def scatter_nd( self: ivy.Container, updates: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, shape: Union[ivy.Array, ivy.NativeArray, ivy.Container] = None, *, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.scatter_nd. This method simply wraps the function, and so the docstring for ivy.scatter_nd also applies to this method with minimal changes. Parameters ---------- self Index array or container. updates values to update input tensor with shape The shape of the result. Default is ``None``, in which case tensor argument must be provided. reduction The reduction method for the scatter, one of 'sum', 'min', 'max' or 'replace' key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret New container of given shape, with the values updated at the indices. Examples -------- scatter into an empty container >>> indices = ivy.Container(a=ivy.array([[4],[3],[6]]), ... b=ivy.array([[5],[1],[2]])) >>> updates = ivy.Container(a=ivy.array([100, 200, 200]), ... b=ivy.array([20, 30, 40])) >>> shape = ivy.Container(a=ivy.array([10]), ... b=ivy.array([10])) >>> z = indices.scatter_nd(updates, shape=shape) >>> print(z) { a: ivy.array([0, 0, 0, 200, 100, 0, 200, 0, 0, 0]), b: ivy.array([0, 30, 40, 0, 0, 20, 0, 0, 0, 0]) } With scatter into a container. >>> indices = ivy.Container(a=ivy.array([[5],[6],[7]]), ... b=ivy.array([[2],[3],[4]])) >>> updates = ivy.Container(a=ivy.array([50, 60, 70]), ... b=ivy.array([20, 30, 40])) >>> z = ivy.Container(a=ivy.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ... b=ivy.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) >>> indices.scatter_nd(updates,reduction='replace', out = z) >>> print(z) { a: ivy.array([1, 2, 3, 4, 5, 50, 60, 70, 9, 10]), b: ivy.array([1, 2, 20, 30, 40, 6, 7, 8, 9, 10]) } """ return self.static_scatter_nd( self, updates, shape=shape, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_scatter_flat( indices: Union[ivy.Array, ivy.NativeArray, ivy.Container], updates: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, size: Optional[int] = None, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.scatter_flat. This method simply wraps the function, and so the docstring for ivy.scatter_flat also applies to this method with minimal changes. Parameters ---------- indices Index array or container. updates values to update input tensor with size The size of the result. reduction The reduction method for the scatter, one of 'sum', 'min', 'max' or 'replace' key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ref New container of given shape, with the values updated at the indices. """ return ContainerBase.cont_multi_map_in_function( "scatter_flat", indices, updates, size=size, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def scatter_flat( self: ivy.Container, updates: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, size: Optional[int] = None, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.scatter_flat. This method simply wraps the function, and so the docstring for ivy.scatter_flat also applies to this method with minimal changes. Parameters ---------- self Index array or container. updates values to update input tensor with size The size of the result. reduction The reduction method for the scatter, one of 'sum', 'min', 'max' or 'replace' key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret New container of given shape, with the values updated at the indices. """ return self.static_scatter_flat( self, updates, size=size, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_gather_nd( params: Union[ivy.Container, ivy.Array, ivy.NativeArray], indices: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, batch_dims: Optional[int] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """Gather slices from all container params into a arrays with shape specified by indices. Parameters ---------- indices Index array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- Container object with all sub-array dimensions gathered. Examples -------- >>> x = ivy.Container(a=ivy.array([[0., 10., 20.],[30.,40.,50.]]), ... b=ivy.array([[0., 100., 200.],[300.,400.,500.]])) >>> y = ivy.Container(a=ivy.array([1,0]), ... b=ivy.array([0])) >>> print(ivy.Container.static_gather_nd(x, y)) { a: ivy.array(30.), b: ivy.array([0., 100., 200.]) } """ return ContainerBase.cont_multi_map_in_function( "gather_nd", params, indices, batch_dims=batch_dims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def gather_nd( self: ivy.Container, indices: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, batch_dims: Optional[int] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.gather_nd. This method simply wraps the function, and so the docstring for ivy.gather_nd also applies to this method with minimal changes. Parameters ---------- self The container from which to gather values. indices Index array or container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as ``x`` if None. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret New container of given shape, with the values gathered at the indices. Examples -------- >>> x = ivy.Container(a=ivy.array([[[0., 10.], [20.,30.]], ... [[40.,50.], [60.,70.]]]), ... b=ivy.array([[[0., 100.], [200.,300.]], ... [[400.,500.],[600.,700.]]])) >>> y = ivy.Container(a=ivy.array([1,0]), ... b=ivy.array([0])) >>> z = x.gather_nd(y) >>> print(z) { a: ivy.array([40., 50.]), b: ivy.array([[0., 100.], [200., 300.]]) } """ return self.static_gather_nd( self, indices, batch_dims=batch_dims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_einops_reduce( x: ivy.Container, pattern: str, reduction: str, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **axes_lengths: Dict[str, int], ) -> ivy.Container: """Perform einops reduce operation on each sub array in the container. Parameters ---------- pattern Reduction pattern. reduction One of available reductions ('min', 'max', 'sum', 'mean', 'prod'), or callable. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. axes_lengths Any additional specifications for dimensions. Returns ------- ivy.Container with each array having einops.reduce applied. Examples -------- >>> x = ivy.Container(a=ivy.array([[-4.47, 0.93, -3.34], ... [3.66, 24.29, 3.64]]), ... b=ivy.array([[4.96, 1.52, -10.67], ... [4.36, 13.96, 0.3]])) >>> reduced = ivy.Container.static_einops_reduce(x, 'a b -> a', 'mean') >>> print(reduced) { a: ivy.array([-2.29, 10.5]), b: ivy.array([-1.4, 6.21]) } """ return ContainerBase.cont_multi_map_in_function( "einops_reduce", x, pattern, reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **axes_lengths, )
[docs]def einops_reduce( self: ivy.Container, pattern: str, reduction: Union[str, Callable], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **axes_lengths: Dict[str, int], ) -> ivy.Container: """ ivy.Container instance method variant of ivy.einops_reduce. This method simply wraps the function, and so the docstring for ivy.einops_reduce also applies to this method with minimal changes. Parameters ---------- self Input container to be reduced. pattern Reduction pattern. reduction One of available reductions ('min', 'max', 'sum', 'mean', 'prod'), or callable. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. axes_lengths Any additional specifications for dimensions. Returns ------- ret New container with einops.reduce having been applied. Examples -------- >>> x = ivy.Container(a=ivy.array([[[5, 4, 3], ... [11, 2, 9]], ... [[3, 5, 7], ... [9, 7, 1]]]), ... b=ivy.array([[[9,7,6], ... [5,2,1]], ... [[4,1,2], ... [2,3,6]], ... [[1, 9, 6], ... [0, 2, 1]]])) >>> reduced = x.einops_reduce('a b c -> a b', 'sum') >>> print(reduced) { a: ivy.array([[12, 22], [15, 17]]), b: ivy.array([[22, 8], [7, 11], [16, 3]]) } """ return self.static_einops_reduce( self, pattern, reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **axes_lengths, )
[docs]def static_einops_repeat( x: ivy.Container, pattern: str, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **axes_lengths: Dict[str, int], ) -> ivy.Container: """Perform einops repeat operation on each sub array in the container. Parameters ---------- pattern Rearrangement pattern. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. axes_lengths Any additional specifications for dimensions. **axes_lengths Returns ------- ivy.Container with each array having einops.repeat applied. Examples -------- >>> x = ivy.Container(a=ivy.array([[30, 40], [50, 75]]), ... b=ivy.array([[1, 2], [4, 5]])) >>> repeated = ivy.Container.static_einops_repeat( ... x, 'h w -> (tile h) w', tile=2) >>> print(repeated) { a: ivy.array([[30, 40], [50, 75], [30, 40], [50, 75]]), b: ivy.array([[1, 2], [4, 5], [1, 2], [4, 5]]) } """ return ContainerBase.cont_multi_map_in_function( "einops_repeat", x, pattern, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **axes_lengths, )
[docs]def einops_repeat( self: ivy.Container, pattern: str, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **axes_lengths: Dict[str, int], ) -> ivy.Container: """ ivy.Container instance method variant of ivy.einops_repeat. This method simply wraps the function, and so the docstring for ivy.einops_repeat also applies to this method with minimal changes. Parameters ---------- self Input array or container to be repeated. pattern Rearrangement pattern. axes_lengths Any additional specifications for dimensions. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret New container with einops.repeat having been applied. Examples -------- >>> x = ivy.Container(a=ivy.array([[30, 40], [50, 75]]), ... b=ivy.array([[1, 2], [4, 5]])) >>> repeated = x.einops_repeat('h w -> h (w tile)', tile=2) >>> print(repeated) { a: ivy.array([[30, 30, 40, 40], [50, 50, 75, 75]]), b: ivy.array([[1, 1, 2, 2], [4, 4, 5, 5]]) } """ return self.static_einops_repeat( self, pattern, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **axes_lengths, )
[docs]def static_value_is_nan( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, include_infs: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.value_is_nan. This method simply wraps the function, and so the docstring for ivy.value_is_nan also applies to this method with minimal changes. Parameters ---------- x input container. include_infs Whether to include infs and -infs in the check. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is None. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean as to whether the input value is a nan or not. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([452]), b=ivy.array([float('inf')])) >>> y = ivy.Container.static_value_is_nan(x) >>> print(y) { a: false, b: true } With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([float('nan')]), b=ivy.array([0])) >>> y = ivy.Container.static_value_is_nan(x) >>> print(y) { a: true, b: false } With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([float('inf')]), b=ivy.array([22])) >>> y = ivy.Container.static_value_is_nan(x, include_infs=False) >>> print(y) { a: false, b: false } """ return ContainerBase.cont_multi_map_in_function( "value_is_nan", x, include_infs=include_infs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def value_is_nan( self: ivy.Container, /, *, include_infs: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.value_is_nan. This method simply wraps the function, and so the docstring for ivy.value_is_nan also applies to this method with minimal changes. Parameters ---------- self input container. include_infs Whether to include infs and -infs in the check. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is None. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Boolean as to whether the input value is a nan or not. Examples -------- >>> x = ivy.Container(a=ivy.array([425]), b=ivy.array([float('nan')])) >>> y = x.value_is_nan() >>> print(y) { a: false, b: true } >>> x = ivy.Container(a=ivy.array([float('inf')]), b=ivy.array([0])) >>> y = x.value_is_nan() >>> print(y) { a: true, b: false } >>> x = ivy.Container(a=ivy.array([float('inf')]), b=ivy.array([22])) >>> y = x.value_is_nan(include_infs=False) >>> print(y) { a: false, b: false } """ return self.static_value_is_nan( self, include_infs=include_infs, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_to_numpy( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, copy: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.to_numpy. This method simply wraps the function, and so the docstring for ivy.to_numpy also applies to this method with minimal changes. Parameters ---------- x input container. copy Whether to copy the input. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a container of numpy arrays copying all the element of the container ``self``. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([1, 0, 1, 1]), ... b=ivy.array([1, -1, 0, 0])) >>> y = ivy.Container.static_to_numpy(x) >>> print(y) { a: array([1, 0, 1, 1], dtype=int32), b: array([1, -1, 0, 0], dtype=int32) } >>> x = ivy.Container(a=ivy.array([1., 0., 0., 1.]), ... b=ivy.native_array([1, 1, -1, 0])) >>> y = ivy.Container.static_to_numpy(x) >>> print(y) { a: array([1., 0., 0., 1.], dtype=float32), b: array([1, 1, -1, 0], dtype=int32) } """ return ContainerBase.cont_multi_map_in_function( "to_numpy", x, copy=copy, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def to_numpy( self: ivy.Container, /, *, copy: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.to_numpy. This method simply wraps the function, and so the docstring for ivy.to_numpy also applies to this method with minimal changes. Parameters ---------- self input container. copy Whether to copy the input. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a container of numpy arrays copying all the element of the container ``self``. Examples -------- With one :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), b=ivy.array([1, 0, 1, 1])) >>> y = x.to_numpy() >>> print(y) { a: array([-1, 0, 1], dtype=int32), b: array([1, 0, 1, 1], dtype=int32) } >>> x = ivy.Container(a=ivy.native_array([[-1, 0, 1], [-1, 0, 1], [1, 0, -1]]), ... b=ivy.native_array([[-1, 0, 0], [1, 0, 1], [1, 1, 1]])) >>> y = x.to_numpy() >>> print(y) { a: array([[-1, 0, 1], [-1, 0, 1], [1, 0, -1]], dtype=int32), b: array([[-1, 0, 0], [1, 0, 1], [1, 1, 1]], dtype=int32) } """ return self.static_to_numpy( self, copy=copy, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_to_scalar( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.to_scalar. This method simply wraps the function, and so the docstring for ivy.to_scalar also applies to this method with minimal changes. Parameters ---------- x input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a container of scalar values copying all the element of the container ``x``. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1]), b=ivy.array([3])) >>> y = ivy.Container.static_to_scalar(x) >>> print(y) { a: -1, b: 3 } """ return ContainerBase.cont_multi_map_in_function( "to_scalar", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def to_scalar( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.to_scalar. This method simply wraps the function, and so the docstring for ivy.to_scalar also applies to this method with minimal changes. Parameters ---------- self input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a container of scalar values copying all the element of the container ``self``. Examples -------- With one :class:`ivy.Container` instance: >>> x = ivy.Container(a=ivy.array([1]), b=ivy.array([0]), ... c=ivy.array([-1])) >>> y = x.to_scalar() >>> print(y) { a: 1, b: 0, c: -1 } """ return self.static_to_scalar( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_to_list( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.to_list. This method simply wraps the function, and so the docstring for ivy.to_list also applies to this method with minimal changes. Parameters ---------- x input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A container with list representation of the leave arrays. Examples -------- With one :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0, 1, 2])) >>> y = ivy.Container.static_to_list(x) >>> print(y) {a:[0,1,2]} """ return ContainerBase.cont_multi_map_in_function( "to_list", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
def to_list( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.to_list. This method simply wraps the function, and so the docstring for ivy.to_list also applies to this method with minimal changes. Parameters ---------- self input container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A container with list representation of the leave arrays. Examples -------- With one :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([0, 1, 2])) >>> y = x.to_list() >>> print(y) {a:[0,1,2]} """ return self.static_to_list( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_stable_divide( numerator: ivy.Container, denominator: Union[Number, ivy.Array, ivy.Container], /, *, min_denominator: Union[ Number, ivy.Array, ivy.NativeArray, ivy.Container ] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.stable_divide. This method simply wraps the function, and so the docstring for ivy.stable_divide also applies to this method with minimal changes. Parameters ---------- numerator Container of the numerators of the division. denominator Container of the denominators of the division. min_denominator Container of the minimum denominator to use, use global ivy._MIN_DENOMINATOR by default. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A container of elements containing the new items following the numerically stable division. Examples -------- >>> x = ivy.Container(a=ivy.asarray([10., 15.]), b=ivy.asarray([20., 25.])) >>> y = ivy.Container.stable_divide(x, 0.5) >>> print(y) { a: ivy.array([20., 30.]), b: ivy.array([40., 50.]) } >>> x = ivy.Container(a=1, b=10) >>> y = ivy.asarray([4, 5]) >>> z = ivy.Container.stable_divide(x, y) >>> print(z) { a: ivy.array([0.25, 0.2]), b: ivy.array([2.5, 2.]) } >>> x = ivy.Container(a=1, b=10) >>> y = np.array((4.5, 9)) >>> z = ivy.Container.stable_divide(x, y) >>> print(z) { a: array([0.22222222, 0.11111111]), b: array([2.22222222, 1.11111111]) } >>> x = ivy.Container(a=ivy.asarray([1., 2.]), b=ivy.asarray([3., 4.])) >>> y = ivy.Container(a=ivy.asarray([0.5, 2.5]), b=ivy.asarray([3.5, 0.4])) >>> z = ivy.Container.stable_divide(x, y) >>> print(z) { a: ivy.array([2., 0.8]), b: ivy.array([0.857, 10.]) } >>> x = ivy.Container(a=ivy.asarray([1., 2.], [3., 4.]), ... b=ivy.asarray([5., 6.], [7., 8.])) >>> y = ivy.Container(a=ivy.asarray([0.5, 2.5]), b=ivy.asarray([3.5, 0.4])) >>> z = ivy.Container.stable_divide(x, y, min_denominator=2) >>> print(z) { a: ivy.array([0.4, 0.444]), b: ivy.array([0.909, 2.5]) } """ return ContainerBase.cont_multi_map_in_function( "stable_divide", numerator, denominator, min_denominator=min_denominator, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def stable_divide( self, denominator: Union[Number, ivy.Array, ivy.NativeArray, ivy.Container], /, *, min_denominator: Union[ Number, ivy.Array, ivy.NativeArray, ivy.Container ] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.stable_divide. This method simply wraps the function, and so the docstring for ivy.stable_divide also applies to this method with minimal changes. Parameters ---------- self input container. denominator Container of the denominators of the division. min_denominator Container of the minimum denominator to use, use global ivy._MIN_DENOMINATOR by default. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a container of numpy arrays copying all the element of the container ``self``. A container of elements containing the new items following the numerically stable division, using ``self`` as the numerator. Examples -------- >>> x = ivy.Container(a=ivy.asarray([3., 6.]), b=ivy.asarray([9., 12.])) >>> y = x.stable_divide(5) >>> print(y) { a: ivy.array([0.6, 1.2]), b: ivy.array([1.8, 2.4]) } >>> x = ivy.Container(a=ivy.asarray([[2., 4.], [6., 8.]]), ... b=ivy.asarray([[10., 12.], [14., 16.]])) >>> z = x.stable_divide(2, min_denominator=2) >>> print(z) { a: ivy.array([[0.5, 1.], [1.5, 2.]]), b: ivy.array([[2.5, 3.], [3.5, 4.]]) } >>> x = ivy.Container(a=ivy.asarray([3., 6.]), b=ivy.asarray([9., 12.])) >>> y = ivy.Container(a=ivy.asarray([6., 9.]), b=ivy.asarray([12., 15.])) >>> z = x.stable_divide(y) >>> print(z) { a: ivy.array([0.5, 0.667]), b: ivy.array([0.75, 0.8]) } """ return self.static_stable_divide( self, denominator, min_denominator=min_denominator, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_stable_pow( base: ivy.Container, exponent: Union[Number, ivy.Array, ivy.Container], /, *, min_base: float = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.stable_pow. This method simply wraps the function, and so the docstring for ivy.stable_pow also applies to this method with minimal changes. Parameters ---------- base Container of the base. exponent Container of the exponent. min_base The minimum base to use, use global ivy._MIN_BASE by default. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. Returns ------- ret A container of elements containing the new items following the numerically stable power. """ return ContainerBase.cont_multi_map_in_function( "stable_pow", base, exponent, min_base=min_base, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def stable_pow( self, exponent: Union[Number, ivy.Array, ivy.NativeArray, ivy.Container], /, *, min_base: float = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.stable_pow. This method simply wraps the function, and so the docstring for ivy.stable_pow also applies to this method with minimal changes. Parameters ---------- self Container of the base. exponent Container of the exponent. min_base The minimum base to use, use global ivy._MIN_BASE by default. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. Returns ------- ret A container of elements containing the new items following the numerically stable power. """ return self.static_stable_pow( self, exponent, min_base=min_base, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_einops_rearrange( x: ivy.Container, pattern: str, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **axes_lengths: Dict[str, int], ) -> ivy.Container: """ ivy.Container static method variant of ivy.einops_rearrange. This method simply wraps the function, and so the docstring for ivy.einops_rearrange also applies to this method with minimal changes. Parameters ---------- pattern Rearrangement pattern. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. axes_lengths Any additional specifications for dimensions. Returns ------- ivy.Container with each array having einops.rearrange applied. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[1, 2, 3], ... [-4, -5, -6]]), ... b=ivy.array([[7, 8, 9], ... [10, 11, 12]])) >>> y = ivy.static_einops_rearrange(x, "height width -> width height") >>> print(y) { a: ivy.array([[1, -4], [2, -5], [3, -6]]), b: ivy.array([[7, 10], [8, 11], [9, 12]]) } >>> x = ivy.Container(a=ivy.array([[[ 1, 2, 3], ... [ 4, 5, 6]], ... [[ 7, 8, 9], ... [10, 11, 12]]])) >>> y = ivy.static_einops_rearrange(x, "c h w -> c (h w)") >>> print(y) { a: (<class ivy.array.array.Array> shape=[2, 6]) } >>> x = ivy.Container(a=ivy.array([[1, 2, 3, 4, 5, 6], ... [7, 8, 9, 10, 11, 12]])) >>> y = ivy.static_einops_rearrange(x, "c (h w) -> (c h) w", h=2, w=3) { a: (<class ivy.array.array.Array> shape=[4, 3]) } """ return ContainerBase.cont_multi_map_in_function( "einops_rearrange", x, pattern, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **axes_lengths, )
[docs]def einops_rearrange( self: ivy.Container, pattern: str, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, **axes_lengths: Dict[str, int], ): """ ivy.Container instance method variant of ivy.einops_rearrange. This method simply wraps the function, and so the docstring for ivy.einops_rearrange also applies to this method with minimal changes. Parameters ---------- pattern Rearrangement pattern. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. axes_lengths Any additional specifications for dimensions. **axes_lengths Returns ------- ivy.Container with each array having einops.rearrange applied. Examples -------- >>> x = ivy.Container(a=ivy.array([[1, 2, 3], ... [-4, -5, -6]]), ... b=ivy.array([[7, 8, 9], ... [10, 11, 12]])) >>> y = x.einops_rearrange("height width -> width height") >>> print(y) { a: ivy.array([[1, -4], [2, -5], [3, -6]]), b: ivy.array([[7, 10], [8, 11], [9, 12]]) } >>> x = ivy.Container(a=ivy.array([[[ 1, 2, 3], ... [ 4, 5, 6]], ... [[ 7, 8, 9], ... [10, 11, 12]]])) >>> y = x.einops_rearrange("c h w -> c (h w)") >>> print(y) { a: (<class ivy.array.array.Array> shape=[2, 6]) } >>> x = ivy.Container(a=ivy.array([[1, 2, 3, 4, 5, 6], ... [7, 8, 9, 10, 11, 12]])) >>> y = x.einops_rearrange("c (h w) -> (c h) w", h=2, w=3) { a: (<class ivy.array.array.Array> shape=[4, 3]) } """ return self.static_einops_rearrange( self, pattern, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **axes_lengths, )
[docs]def static_clip_matrix_norm( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], max_norm: float, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, p: float = 2.0, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.clip_matrix_norm. This method simply wraps the function, and so the docstring for ivy.clip_matrix_norm also applies to this method with minimal changes. Parameters ---------- x Input array containing elements to clip. max_norm The maximum value of the array norm. p The p-value for computing the p-norm. Default is 2. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret An array with the matrix norm downscaled to the max norm if needed. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), ... b=ivy.array([[3., 4., 5.]])) >>> y = ivy.Container.static_clip_matrix_norm(x, 2.0) >>> print(y) { a: ivy.array([[0., 0.894, 1.79]]), b: ivy.array([[0.849, 1.13, 1.41]]) } """ return ContainerBase.cont_multi_map_in_function( "clip_matrix_norm", x, max_norm, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, p=p, out=out, )
[docs]def clip_matrix_norm( self: ivy.Container, max_norm: float, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, p: float = 2.0, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.clip_matrix_norm. This method simply wraps the function, and so the docstring for ivy.clip_matrix_norm also applies to this method with minimal changes. Parameters ---------- self Input array containing elements to clip. max_norm The maximum value of the array norm. p The p-value for computing the p-norm. Default is 2. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret An array with the matrix norm downscaled to the max norm if needed. Examples -------- With :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), ... b=ivy.array([[3., 4., 5.]])) >>> y = x.clip_matrix_norm(2.0, p=1.0) >>> print(y) { a: ivy.array([[0., 1., 2.]]), b: ivy.array([[1.2, 1.6, 2.]]) } """ return self.static_clip_matrix_norm( self, max_norm, p=p, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_supports_inplace_updates( x: Union[ivy.Dtype, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.supports_inplace. This method simply wraps the function, and so the docstring for ivy.supports_inplace also applies to this method with minimal changes. Parameters ---------- x An ivy.Container. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret An ivy.Container instance of bool values. True if nodes of x support in-place operations. False otherwise. Raises ------ ValueError If a node(s) of the container isn't a class instance of ivy.Array or ivy.NativeArray, an exception will be raised. Examples -------- With `ivy.Container` input and backend set as 'numpy': >>> x = ivy.Container(a = ivy.array(1.0), b=ivy.array(2)) >>> ret = ivy.Container.static_supports_inplace_updates(x) >>> print(ret) { a: true, b: true } With `ivy.Container` input and backend set as 'tensorflow': >>> x = ivy.Container(a=ivy.array(ivy.array([2.0, 0.0])), ... b=ivy.array([0., 5.5, -8])) >>> ret = ivy.Container.static_supports_inplace_updates(x) >>> print(ret) { a: true, b: false } """ return ContainerBase.cont_multi_map_in_function( "supports_inplace_updates", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def supports_inplace_updates( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.supports_inplace_updates. This method simply wraps the static function, and so the docstring for the static variant also applies to this method with minimal changes. Parameters ---------- self An ivy.Container whose elements are data types supported by Ivy. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret An ivy.Container instance of bool values. True if nodes of the Container support in-place operations. False otherwise. Examples -------- With an `ivy.Container` instance and backend set as 'numpy': >>> x = ivy.Container(a = ivy.array(1.0), b=ivy.array(2)) >>> ret = x.supports_inplace_updates() >>> print(ret) { a: false, b: false } With an `ivy.Container` instance and backend set as 'tensorflow': >>> x = ivy.Container(a=ivy.variable(ivy.array([2.0, 0.0])), ... b=ivy.array([0., 5.5, -8])) >>> ret = x.supports_inplace_updates() >>> print(ret) { a: false, b: false } """ return ContainerWithGeneral.static_supports_inplace_updates( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_get_num_dims( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, as_array: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.get_num_dims. This method simply wraps the function, and so the docstring for ivy.get_num_dims also applies to this method with minimal changes. Parameters ---------- x ivy.Container to infer the number of dimensions for as_array Whether to return the shape as a array, default False. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Shape of the array Examples -------- >>> x = ivy.Container(b = ivy.asarray([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]])) >>> ivy.Container.static_get_num_dims(x) { b: 2 } >>> x = ivy.Container(b = ivy.array([[[0,0,0],[0,0,0],[0,0,0]] ... [[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]]])) >>> ivy.Container.static_get_num_dims(x) { b: 3 } >>> x = ivy.Container(b = ivy.array([[[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]]]), ... c = ivy.asarray([[0.,1.,1.],[8.,2.,3.]])) >>> ivy.Container.static_get_num_dims(x) { b: 3, c: 2 } >>> ivy.Container.static_get_num_dims(x, as_array=True) { b: ivy.array(3), c: ivy.array(2) } """ return ContainerBase.cont_multi_map_in_function( "get_num_dims", x, as_array=as_array, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def get_num_dims( self: ivy.Container, /, *, as_array: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.get_num_dims. This method simply wraps the function, and so the docstring for ivy.get_num_dims also applies to this method with minimal changes. Parameters ---------- self ivy.Container to infer the number of dimensions for as_array Whether to return the shape as a array, default False. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Shape of the array Examples -------- >>> a = ivy.Container(b = ivy.asarray([[0.,1.,1.],[1.,0.,0.],[8.,2.,3.]])) >>> a.get_num_dims() { b: 2 } >>> a = ivy.Container(b = ivy.array([[[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]]])) >>> a.get_num_dims() { b: 3 } >>> a = ivy.Container(b = ivy.array([[[0,0,0],[0,0,0],[0,0,0]], ... [[0,0,0],[0,0,0],[0,0,0]]]), ... c = ivy.asarray([[0.,1.,1.],[8.,2.,3.]])) >>> a.get_num_dims() { b: 3, c: 2 } >>> a.get_num_dims(as_array=True) { b: ivy.array(3), c: ivy.array(2) } """ return ContainerWithGeneral.static_get_num_dims( self, as_array=as_array, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_array_equal( x0: Union[ivy.Array, ivy.NativeArray, ivy.Container], x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.array_equal. This method simply wraps the function, and so the docstring for ivy.array_equal also applies to this method with minimal changes. Parameters ---------- x0 The first input container to compare. x1 The second input container to compare. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A boolean container indicating whether the two containers are equal at each level. Examples -------- >>> a = ivy.array([[0., 1.], [1. ,0.]]) >>> b = ivy.array([[-2., 1.], [1. ,2.]]) >>> c = ivy.array([[0., 1.], [1. ,0.]]) >>> d = ivy.array([[2., 1.], [1. ,2.]]) >>> a0 = ivy.Container(a = a, b = b) >>> a1 = ivy.Container(a = c, b = d) >>> y = ivy.Container.static_array_equal(a0, a1) >>> print(y) { a: true, b: false } """ return ContainerBase.cont_multi_map_in_function( "array_equal", x0, x1, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def array_equal( self: Union[ivy.Array, ivy.NativeArray, ivy.Container], x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.array_equal. This method simply wraps the function, and so the docstring for ivy.array_equal also applies to this method with minimal changes. Parameters ---------- self The first input container to compare. x The second input container to compare. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A boolean container indicating whether the two containers are equal at each level. Examples -------- >>> a = ivy.array([[0., 1.], [1. ,0.]]) >>> b = ivy.array([[-2., 1.], [1. ,2.]]) >>> c = ivy.array([[0., 1.], [1. ,0.]]) >>> d = ivy.array([[2., 1.], [1. ,2.]]) >>> a0 = ivy.Container(a = a, b = b) >>> a1 = ivy.Container(a = c, b = d) >>> y = a0.array_equal(a1) >>> print(y) { a: true, b: false } """ return ContainerWithGeneral.static_array_equal( self, x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
#ivy.container.gradients from typing import Optional, Union, List, Dict # local import ivy from ivy.container.base import ContainerBase # noinspection PyMissingConstructor
[docs]def static_stop_gradient( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, preserve_type: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.stop_gradient. This method simply wraps the function, and so the docstring for ivy.stop_gradient also applies to this method with minimal changes. Parameters ---------- x Array or Container for which to stop the gradient. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. preserve_type Whether to preserve gradient computation on ivy.Array instances. Default is True. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The same array x, but with no gradient information. Examples -------- With one :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_stop_gradient(x, preserve_type=False) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., 5.]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> ivy.Container.static_stop_gradient(x, preserve_type=True, out=x) >>> print(x) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., 5.]) } """ return ContainerBase.cont_multi_map_in_function( "stop_gradient", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, preserve_type=preserve_type, out=out, )
[docs]def stop_gradient( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, preserve_type: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.stop_gradient. This method simply wraps the function, and so the docstring for ivy.stop_gradient also applies to this method with minimal changes. Parameters ---------- self Container for which to stop the gradient. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. preserve_type Whether to preserve gradient computation on ivy.Array instances. Default is True. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The same array x, but with no gradient information. Examples -------- With one :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> y = x.stop_gradient(preserve_type=False) >>> print(y) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., 5.]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> x.stop_gradient(preserve_type=True, out=x) >>> print(x) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., 5.]) } """ return self.static_stop_gradient( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, preserve_type=preserve_type, out=out, )
[docs]def adam_step( self: ivy.Container, mw: Union[ivy.Array, ivy.NativeArray, ivy.Container], vw: Union[ivy.Array, ivy.NativeArray, ivy.Container], step: Union[int, float], /, *, beta1: float = 0.9, beta2: float = 0.999, epsilon: float = 1e-7, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.adam_step. This method simply wraps the function, and so the docstring for ivy.adam_step also applies to this method with minimal changes. Parameters ---------- self Derivates of the cost c with respect to the weights ws, [dc/dw for w in ws]. mw running average of the gradients. vw running average of second moments of the gradients. step training step. beta1 gradient forgetting factor (Default value = 0.9). beta2 second moment of gradient forgetting factor (Default value = 0.999). epsilon divisor during adam update, preventing division by zero (Default value = 1e-7). out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The adam step delta. Examples -------- With one :class:`ivy.Container` input: >>> dcdw = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> mw = ivy.array([1., 4., 9.]) >>> vw = ivy.array([0.,]) >>> step = ivy.array([3.4]) >>> beta1 = 0.87 >>> beta2 = 0.976 >>> epsilon = 1e-5 >>> adam_step_delta = dcdw.adam_step(mw, vw, step, beta1=beta1, beta2=beta2, ... epsilon=epsilon) >>> print(adam_step_delta) ({ a: ivy.array([6.49e+04, 1.74e+01, 1.95e+01]), b: ivy.array([2.02, 4.82, 8.17]) }, { a: ivy.array([0.87, 3.61, 8.09]), b: ivy.array([1.26, 4., 8.48]) }, { a: ivy.array([0., 0.024, 0.096]), b: ivy.array([0.216, 0.384, 0.6]) }) With multiple :class:`ivy.Container` inputs: >>> dcdw = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> mw = ivy.Container(a=ivy.array([0., 0., 0.]), ... b=ivy.array([0., 0., 0.])) >>> vw = ivy.Container(a=ivy.array([0.,]), ... b=ivy.array([0.,])) >>> step = ivy.array([3.4]) >>> beta1 = 0.87 >>> beta2 = 0.976 >>> epsilon = 1e-5 >>> adam_step_delta = dcdw.adam_step(mw, vw, step, beta1=beta1, beta2=beta2, ... epsilon=epsilon) >>> print(adam_step_delta) ({ a: ivy.array([0., 0.626, 0.626]), b: ivy.array([0.626, 0.626, 0.626]) }, { a: ivy.array([0., 0.13, 0.26]), b: ivy.array([0.39, 0.52, 0.65]) }, { a: ivy.array([0., 0.024, 0.096]), b: ivy.array([0.216, 0.384, 0.6]) }) """ return ivy.adam_step( self, mw, vw, step, beta1=beta1, beta2=beta2, epsilon=epsilon, out=out )
[docs]def optimizer_update( self: ivy.Container, effective_grad: Union[ivy.Array, ivy.NativeArray, ivy.Container], lr: Union[float, ivy.Array, ivy.NativeArray, ivy.Container], /, *, stop_gradients: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """Update weights ws of some function, given the true or effective derivatives of some cost c with respect to ws, [dc/dw for w in ws]. Parameters ---------- self Weights of the function to be updated. effective_grad Effective gradients of the cost c with respect to the weights ws, [dc/dw for w in ws]. lr Learning rate(s), the rate(s) at which the weights should be updated relative to the gradient. stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The new function weights ws_new, following the optimizer updates. Examples -------- With one :class:`ivy.Container` input: >>> w = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> effective_grad = ivy.array([0., 0., 0.]) >>> lr = 3e-4 >>> ws_new = w.optimizer_update(effective_grad, lr) >>> print(ws_new) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., 5.]) } With multiple :class:`ivy.Container` inputs: >>> w = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> effective_grad = ivy.Container(a=ivy.array([0., 0., 0.]), ... b=ivy.array([0., 0., 0.])) >>> lr = 3e-4 >>> ws_new = w.optimizer_update(effective_grad, lr, out=w) >>> print(w) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., 5.]) } >>> w = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> effective_grad = ivy.Container(a=ivy.array([0., 0., 0.]), ... b=ivy.array([0., 0., 0.])) >>> lr = ivy.array([3e-4]) >>> ws_new = w.optimizer_update(effective_grad, lr, stop_gradients=False) >>> print(ws_new) { a: ivy.array([0., 1., 2.]), b: ivy.array([3., 4., 5.]) } """ return ivy.optimizer_update( self, effective_grad, lr, stop_gradients=stop_gradients, out=out )
[docs]def gradient_descent_update( self: ivy.Container, dcdw: Union[ivy.Array, ivy.NativeArray, ivy.Container], lr: Union[float, ivy.Array, ivy.NativeArray, ivy.Container], /, *, stop_gradients: bool = True, out: ivy.Container = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.gradient_descent_update. This method simply wraps the function, and so the docstring for ivy.gradient_descent_update also applies to this method with minimal changes. Parameters ---------- self Weights of the function to be updated. dcdw Derivates of the cost c with respect to the weights ws, [dc/dw for w in ws]. lr Learning rate(s), the rate(s) at which the weights should be updated relative to the gradient. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The new weights, following the gradient descent updates. Examples -------- With one :class:`ivy.Container` inputs: >>> w = ivy.Container(a=ivy.array([1., 2., 3.]), ... b=ivy.array([3.48, 5.72, 1.98])) >>> dcdw = ivy.array([0.5, 0.2, 0.1]) >>> lr = ivy.array(0.3) >>> w_new = w.gradient_descent_update(dcdw, lr) >>> print(w_new) { a: ivy.array([0.85, 1.94, 2.97]), b: ivy.array([3.33, 5.66, 1.95]) } With multiple :class:`ivy.Container` inputs: >>> w = ivy.Container(a=ivy.array([1., 2., 3.]), ... b=ivy.array([3.48, 5.72, 1.98])) >>> dcdw = ivy.Container(a=ivy.array([0.5, 0.2, 0.1]), ... b=ivy.array([2., 3.42, 1.69])) >>> lr = ivy.array(0.3) >>> w_new = w.gradient_descent_update(dcdw, lr) >>> print(w_new) { a: ivy.array([0.85, 1.94, 2.97]), b: ivy.array([2.88, 4.69, 1.47]) } """ return ivy.gradient_descent_update( self, dcdw, lr, stop_gradients=stop_gradients, out=out, )
[docs]def lars_update( self: ivy.Container, dcdw: Union[ivy.Array, ivy.NativeArray, ivy.Container], lr: Union[float, ivy.Array, ivy.NativeArray, ivy.Container], /, *, decay_lambda: float = 0, stop_gradients: bool = True, out: Optional[ivy.Container] = None, ): """Update weights ws of some function, given the derivatives of some cost c with respect to ws, [dc/dw for w in ws], by applying Layerwise Adaptive Rate Scaling (LARS) method. Parameters ---------- self Weights of the function to be updated. dcdw Derivates of the cost c with respect to the weights ws, [dc/dw for w in ws]. lr Learning rate, the rate at which the weights should be updated relative to the gradient. decay_lambda The factor used for weight decay. Default is zero. stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The new function weights ws_new, following the LARS updates. """ return ivy.lars_update( self, dcdw, lr, decay_lambda=decay_lambda, stop_gradients=stop_gradients, out=out, )
[docs]def adam_update( self: ivy.Container, dcdw: Union[ivy.Array, ivy.NativeArray, ivy.Container], lr: Union[float, ivy.Array, ivy.NativeArray, ivy.Container], mw_tm1: Union[ivy.Array, ivy.NativeArray, ivy.Container], vw_tm1: Union[ivy.Array, ivy.NativeArray, ivy.Container], step: int, /, *, beta1: float = 0.9, beta2: float = 0.999, epsilon: float = 1e-7, stop_gradients: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """Update weights ws of some function, given the derivatives of some cost c with respect to ws, using ADAM update. `[reference] <https://en.wikipedia.org/wiki/Stochastic_gradient_descent#Adam>`_ Parameters ---------- self Weights of the function to be updated. dcdw Derivates of the cost c with respect to the weights ws, [dc/dw for w in ws]. lr Learning rate(s), the rate(s) at which the weights should be updated relative to the gradient. mw_tm1 running average of the gradients, from the previous time-step. vw_tm1 running average of second moments of the gradients, from the previous time-step. step training step. beta1 gradient forgetting factor (Default value = 0.9). beta2 second moment of gradient forgetting factor (Default value = 0.999). epsilon divisor during adam update, preventing division by zero (Default value = 1e-7). stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The new function weights ws_new, and also new mw and vw, following the adam updates. Examples -------- With one :class:`ivy.Container` inputs: >>> w = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([4., 5., 6.])) >>> dcdw = ivy.array([1., 0.2, 0.4]) >>> mw_tm1 = ivy.array([0., 0., 0.]) >>> vw_tm1 = ivy.array([0.]) >>> lr = ivy.array(0.01) >>> step = 2 >>> updated_weights = w.adam_update(dcdw, mw_tm1, vw_tm1, lr, step) >>> print(updated_weights) ({ a: ivy.array([1., 2., 3.]), b: ivy.array([4., 5., 6.]) }, ivy.array([0.1 , 0.02, 0.04]), ivy.array([0.01099, 0.01003, 0.01015])) With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> dcdw = ivy.Container(a=ivy.array([0.1,0.3,0.3]), ... b=ivy.array([0.3,0.2,0.2])) >>> lr = ivy.array(0.001) >>> mw_tm1 = ivy.Container(a=ivy.array([0.,0.,0.]), ... b=ivy.array([0.,0.,0.])) >>> vw_tm1 = ivy.Container(a=ivy.array([0.,]), ... b=ivy.array([0.,])) >>> step = 3 >>> beta1 = 0.9 >>> beta2 = 0.999 >>> epsilon = 1e-7 >>> stop_gradients = False >>> updated_weights = w.adam_update(dcdw, lr, mw_tm1, vw_tm1, step, beta1=beta1, ... beta2=beta2, epsilon=epsilon, ... stop_gradients=stop_gradients) >>> print(updated_weights) ({ a: ivy.array([0.99936122, 1.99936116, 2.99936128]), b: ivy.array([3.99936128, 4.99936104, 5.99936104]) }, { a: ivy.array([0.01, 0.03, 0.03]), b: ivy.array([0.03, 0.02, 0.02]) }, { a: ivy.array([1.00000016e-05, 9.00000086e-05, 9.00000086e-05]), b: ivy.array([9.00000086e-05, 4.00000063e-05, 4.00000063e-05]) }) """ return ivy.adam_update( self, dcdw, lr, mw_tm1, vw_tm1, step, beta1=beta1, beta2=beta2, epsilon=epsilon, stop_gradients=stop_gradients, out=out, )
[docs]def lamb_update( self: ivy.Container, dcdw: Union[ivy.Array, ivy.NativeArray, ivy.Container], lr: Union[float, ivy.Array, ivy.NativeArray, ivy.Container], mw_tm1: Union[ivy.Array, ivy.NativeArray, ivy.Container], vw_tm1: Union[ivy.Array, ivy.NativeArray, ivy.Container], step: int, /, *, beta1: float = 0.9, beta2: float = 0.999, epsilon: float = 1e-7, max_trust_ratio: Union[int, float] = 10, decay_lambda: float = 0, stop_gradients: bool = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """Update weights ws of some function, given the derivatives of some cost c with respect to ws, [dc/dw for w in ws], by applying LAMB method. Parameters ---------- self Weights of the function to be updated. dcdw Derivates of the cost c with respect to the weights ws, [dc/dw for w in ws]. lr Learning rate(s), the rate(s) at which the weights should be updated relative to the gradient. mw_tm1 running average of the gradients, from the previous time-step. vw_tm1 running average of second moments of the gradients, from the previous time-step. step training step. beta1 gradient forgetting factor (Default value = 0.9). beta2 second moment of gradient forgetting factor (Default value = 0.999). epsilon divisor during adam update, preventing division by zero (Default value = 1e-7). max_trust_ratio The maximum value for the trust ratio. Default is 10. decay_lambda The factor used for weight decay. Default is zero. stop_gradients Whether to stop the gradients of the variables after each gradient step. Default is ``True``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The new function weights ws_new, following the LAMB updates. Examples -------- With one :class:`ivy.Container` inputs: >>> w = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([4., 5., 6.])) >>> dcdw = ivy.array([3., 4., 5.]) >>> mw_tm1 = ivy.array([0., 0., 0.]) >>> vw_tm1 = ivy.array([0.]) >>> lr = ivy.array(1.) >>> step = ivy.array([2]) >>> new_weights = w.lamb_update(dcdw, mw_tm1, vw_tm1, lr, step) >>> print(new_weights) ({ a: ivy.array([1., 2., 3.]), b: ivy.array([4., 5., 6.]) }, ivy.array([0.3, 0.4, 0.5]), ivy.array([1.01, 1.01, 1.02])) With multiple :class:`ivy.Container` inputs: >>> w = ivy.Container(a=ivy.array([1.,3.,5.]), ... b=ivy.array([3.,4.,2.])) >>> dcdw = ivy.Container(a=ivy.array([0.2,0.3,0.6]), ... b=ivy.array([0.6,0.4,0.7])) >>> mw_tm1 = ivy.Container(a=ivy.array([0.,0.,0.]), ... b=ivy.array([0.,0.,0.])) >>> vw_tm1 = ivy.Container(a=ivy.array([0.,]), ... b=ivy.array([0.,])) >>> step = ivy.array([3.4]) >>> beta1 = 0.9 >>> beta2 = 0.999 >>> epsilon = 1e-7 >>> max_trust_ratio = 10 >>> decay_lambda = 0 >>> stop_gradients = True >>> lr = ivy.array(0.5) >>> new_weights = w.lamb_update(dcdw, lr, mw_tm1, vw_tm1, step, beta1=beta1, ... beta2=beta2, epsilon=epsilon, ... max_trust_ratio=max_trust_ratio, ... decay_lambda=decay_lambda, ... stop_gradients=stop_gradients) >>> print(new_weights) ({ a: ivy.array([-0.708, 1.29, 3.29]), b: ivy.array([1.45, 2.45, 0.445]) }, { a: ivy.array([0.02, 0.03, 0.06]), b: ivy.array([0.06, 0.04, 0.07]) }, { a: ivy.array([4.0e-05, 9.0e-05, 3.6e-04]), b: ivy.array([0.00036, 0.00016, 0.00049]) }) """ return ivy.lamb_update( self, dcdw, lr, mw_tm1, vw_tm1, step, beta1=beta1, beta2=beta2, epsilon=epsilon, max_trust_ratio=max_trust_ratio, decay_lambda=decay_lambda, stop_gradients=stop_gradients, out=out, )
#ivy.container.layers # global from typing import Optional, Tuple, Union, List, Callable, Dict # local from ivy.container.base import ContainerBase import ivy # ToDo: implement all methods here as public instance methods # noinspection PyMissingConstructor
[docs]def static_linear( x: ivy.Container, weight: Union[ivy.Array, ivy.NativeArray], /, *, bias: Optional[Union[ivy.Array, ivy.NativeArray]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.linear. This method simply wraps the function, and so the docstring for ivy.linear also applies to this method with minimal changes. Parameters ---------- x The input x to compute linear transformation on. *[outer_batch_shape,inner_batch_shape,in_features]* weight The weight matrix. *[outer_batch_shape,out_features,in_features]* bias The bias vector, default is ``None``. *[outer_batch_shape,out_features]* key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Result array of the linear transformation. *[outer_batch_shape,inner_batch_shape,out_features]* Examples -------- >>> x = ivy.Container(a=ivy.array([[1.1, 2.2, 3.3], \ [11., 22., 33.]]), \ b=ivy.array([[1.245, 0.278, 4.105], \ [7., 13., 17.]])) >>> w = ivy.array([[1., 2., 3.], \ [4., 5., 6.], \ [7., 8., 9.]]) >>> b = ivy.array([1., 0., -1.]) >>> y = ivy.Container.static_linear(x, w, bias=b) >>> print(y) { a: ivy.array([[16.4, 35.2, 54.], [155., 352., 549.]]), b: ivy.array([[15.1, 31., 46.9], [85., 195., 305.]]) } >>> x = ivy.Container(a=ivy.array([[1.1, 2.2, 3.3], \ [.0, .1, .2]]), \ b=ivy.array([[1.245, 0.278, 4.105], \ [.7, .8, .9]])) >>> w = ivy.Container(a=ivy.array([[1., 2., 3.]]), \ b=ivy.array([[.1, .2, .3]])) >>> b = ivy.Container(a=ivy.array([1.]), b=ivy.array([-1.])) >>> y = ivy.Container.static_linear(x, w, bias=b) >>> print(y) { a: ivy.array([[16.4], [1.8]]), b: ivy.array([[0.412], [-0.5]]) } """ return ContainerBase.cont_multi_map_in_function( "linear", x, weight, bias=bias, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def linear( self: ivy.Container, weight: Union[ivy.Array, ivy.NativeArray], /, *, bias: Optional[Union[ivy.Array, ivy.NativeArray]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.linear. This method simply wraps the function, and so the docstring for ivy.linear also applies to this method with minimal changes. Parameters ---------- self The input container to compute linear transformation on. *[outer_batch_shape,inner_batch_shape,in_features]* weight The weight matrix. *[outer_batch_shape,out_features,in_features]* bias The bias vector, default is ``None``. *[outer_batch_shape,out_features]* key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Result array of the linear transformation. *[outer_batch_shape,inner_batch_shape,out_features]* Examples -------- >>> x = ivy.Container(a=ivy.array([[1.1, 2.2, 3.3], \ [11., 22., 33.]]), \ b=ivy.array([[1.245, 0.278, 4.105], \ [7., 13., 17.]])) >>> w = ivy.array([[1., 2., 3.], \ [4., 5., 6.], \ [7., 8., 9.]]) >>> b = ivy.array([1, 0, -1]) >>> y = x.linear(w, bias=b) >>> print(y) { a: ivy.array([[16.4, 35.2, 54.], \ [155., 352., 549.]]), \ b: ivy.array([[15.1, 31., 46.9], \ [85., 195., 305.]]) } """ return self.static_linear( self, weight, bias=bias, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_dropout( x: ivy.Container, prob: float, /, *, scale: bool = True, dtype: ivy.Dtype = None, training_mode: bool = True, seed: int = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.dropout. This method simply wraps the function, and so the docstring for ivy.dropout also applies to this method with minimal changes. Parameters ---------- x The input container x to perform dropout on. prob The probability of zeroing out each array element, float between 0 and 1. scale Whether to scale the output by `1/(1-prob)`, default is ``True``. dtype output array data type. If dtype is None, the output array data type must be inferred from x. Default: ``None``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Result array of the output after dropout is performed. Examples -------- >>> x = ivy.Container(a=ivy.array([[1., 2., 3.], [4., 5., 6.]]), ... b=ivy.array([7., 8., 9.])) >>> y = ivy.Container.static_dropout(x, 0.3) >>> print(y) { a: ivy.array([[0., 0., 4.28571415], [5.71428585, 7.14285755, 0.]]), b: ivy.array([0., 11.4285717, 12.8571434]) } """ return ContainerBase.cont_multi_map_in_function( "dropout", x, prob, scale=scale, dtype=dtype, training_mode=training_mode, seed=seed, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def dropout( self: ivy.Container, prob: float, /, *, scale: bool = True, dtype: ivy.Dtype = None, training_mode: bool = True, seed: int = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.dropout. This method simply wraps the function, and so the docstring for ivy.dropout also applies to this method with minimal changes. Parameters ---------- self The input container x to perform dropout on. prob The probability of zeroing out each array element, float between 0 and 1. scale Whether to scale the output by `1/(1-prob)`, default is ``True``. dtype output array data type. If dtype is None, the output array data type must be inferred from x. Default: ``None``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Result array of the output after dropout is performed. Examples -------- >>> x = ivy.Container(a=ivy.array([[1., 2., 3.], [4., 5., 6.]]), ... b=ivy.array([7., 8., 9.])) >>> y = x.dropout(0.3) >>> print(y) { a: ivy.array([[0., 0., 4.28571415], [5.71428585, 7.14285755, 0.]]), b: ivy.array([0., 11.4285717, 12.8571434]) } """ return self.static_dropout( self, prob, scale=scale, dtype=dtype, training_mode=training_mode, seed=seed, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
def static_dropout1d( x: ivy.Container, prob: float, /, *, training: bool = True, data_format: str = "NWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "dropout1d", x, prob, training=training, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, ) def dropout1d( self: ivy.Container, prob: float, /, *, training: bool = True, data_format: str = "NWC", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_dropout1d( self, prob, training=training, data_format=data_format, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_scaled_dot_product_attention( q: Union[ivy.Array, ivy.NativeArray, ivy.Container], k: Union[ivy.Array, ivy.NativeArray, ivy.Container], v: Union[ivy.Array, ivy.NativeArray, ivy.Container], scale: float, /, *, mask: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: """ ivy.Container static method variant of ivy.scaled_dot_product_attention. This method simply wraps the function, and so the docstring for ivy.scaled_dot_product_attention also applies to this method with minimal changes. Parameters ---------- self The queries input container. The shape of queries input array leaves should be in *[batch_shape,num_queries,feat_dim]*. The queries input array leaves should have the same size as keys and values. k The keys input array container. The shape of keys input array leaves should be in *[batch_shape,num_keys,feat_dim]*. The keys input array leaves should have the same size as queries and values. v The values input array container. The shape of values input array leaves should be in *[batch_shape,num_keys,feat_dim]*. The values input array leaves should have the same size as queries and keys. scale The scale float value. The scale float value is used to scale the query-key pairs before softmax. mask The mask input array/container. The mask to apply to the query-key values. Default is None. The shape of mask input array leaves should be in *[batch_shape,num_queries,num_keys]*. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The output container following applications of scaled dot-product attention. The output array is the weighted sum produced by the attention score and value. The shape of output array is *[batch_shape,num_queries,feat_dim]* . Examples -------- With :class:`ivy.Container` input: >>> q = ivy.Container(a=ivy.array([[[0.2, 1.], [2.7, 3.], [4.4, 5.6]]]), ... b=ivy.array([[[1.2, 1.], [2.2, 3.], [4.4, 5.6]]])) >>> k = ivy.Container(a=ivy.array([[[4.2, 1.], [2.2, 3.3],[4.4, 5.6]]]), ... b=ivy.array([[[3.2, 1.], [2.2, 3.6], [4.0, 5.6]]])) >>> v = ivy.Container(a=ivy.array([[[5.2, 1.], [2.1, 3.],[4.4, 5.6]]]), ... b=ivy.array([[[0.2, 1.], [2.2, 3.],[4.4, 5.6]]])) >>> mask = ... ivy.Container(a=ivy.array([[[1.0, 1.0, 1.0], ... [1.0, 1.0, 1.0], ... [1.0, 1.0,1.0]]]), ... b=ivy.array([[[1.0, 1.0, 1.0], ... [1.0, 1.0, 1.0], ... [1.0, 1.0,1.0]]])) >>> result = ivy.Container.static_scaled_dot_product_attention(q, k, v, 1, mask=mask) >>> print(result) { a: ivy.array([[[4.27, 5.4], [4.4, 5.6], [4.4, 5.6]]]), b: ivy.array([[[4.35, 5.54], [4.4, 5.6], [4.4, 5.6]]]) } """ return ContainerBase.cont_multi_map_in_function( "scaled_dot_product_attention", q, k, v, scale, mask=mask, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def scaled_dot_product_attention( self: ivy.Container, k: Union[ivy.Array, ivy.NativeArray, ivy.Container], v: Union[ivy.Array, ivy.NativeArray, ivy.Container], scale: float, /, *, mask: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: """ ivy.Container method variant of ivy.scaled_dot_product_attention. This method simply wraps the function, and so the docstring for ivy.scaled_dot_product_attention also applies to this method with minimal changes. Parameters ---------- self The queries input container. The shape of queries input array leaves should be in *[batch_shape,num_queries,feat_dim]*. The queries input array leaves should have the same size as keys and values. k The keys input array container. The shape of keys input array leaves should be in *[batch_shape,num_keys,feat_dim]*. The keys input array leaves should have the same size as queries and values. v The values input array container. The shape of values input array leaves should be in *[batch_shape,num_keys,feat_dim]*. The values input array leaves should have the same size as queries and keys. scale The scale float value. The scale float value is used to scale the query-key pairs before softmax. mask The mask input array/container. The mask to apply to the query-key values. Default is None. The shape of mask input array leaves should be in *[batch_shape,num_queries,num_keys]*. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The output container following applications of scaled dot-product attention. The output array is the weighted sum produced by the attention score and value. The shape of output array is *[batch_shape,num_queries,feat_dim]* . Examples -------- With :class:`ivy.Container` input: >>> q = ivy.Container(a=ivy.array([[[0.2, 1.], [2.7, 3.], [4.4, 5.6]]]), ... b=ivy.array([[[1.2, 1.], [2.2, 3.], [4.4, 5.6]]])) >>> k = ivy.Container(a=ivy.array([[[4.2, 1.], [2.2, 3.3],[4.4, 5.6]]]), ... b=ivy.array([[[3.2, 1.], [2.2, 3.6], [4.0, 5.6]]])) >>> v = ivy.Container(a=ivy.array([[[5.2, 1.], [2.1, 3.],[4.4, 5.6]]]), ... b=ivy.array([[[0.2, 1.], [2.2, 3.],[4.4, 5.6]]])) >>> mask = ... ivy.Container(a=ivy.array([[[1.0, 1.0, 1.0], ... [1.0, 1.0, 1.0], ... [1.0, 1.0,1.0]]]), ... b=ivy.array([[[1.0, 1.0, 1.0], ... [1.0, 1.0, 1.0], ... [1.0, 1.0,1.0]]])) >>> result = q.scaled_dot_product_attention(k, v, 1, mask=mask) >>> print(result) { a: ivy.array([[[4.27, 5.4], [4.4, 5.6], [4.4, 5.6]]]), b: ivy.array([[[4.35, 5.54], [4.4, 5.6], [4.4, 5.6]]]) } """ return self.static_scaled_dot_product_attention( self, k, v, scale, mask=mask, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_multi_head_attention( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], scale, num_heads, /, *, context: Union[ivy.Array, ivy.NativeArray, ivy.Container] = None, mask: Union[ivy.Array, ivy.NativeArray, ivy.Container] = None, to_q_fn: Callable = None, to_kv_fn: Callable = None, to_out_fn: Callable = None, to_q_v=None, to_kv_v=None, to_out_v=None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Union[ivy.Array, ivy.Container]] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: return ContainerBase.cont_multi_map_in_function( "multi_head_attention", x, scale, num_heads, context=context, mask=mask, to_q_fn=to_q_fn, to_kv_fn=to_kv_fn, to_out_fn=to_out_fn, to_q_v=to_q_v, to_kv_v=to_kv_v, to_out_v=to_out_v, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def multi_head_attention( self: ivy.Container, scale, num_heads, /, *, context: Union[ivy.Array, ivy.NativeArray, ivy.Container] = None, mask: Union[ivy.Array, ivy.NativeArray, ivy.Container] = None, to_q_fn: Callable = None, to_kv_fn: Callable = None, to_out_fn: Callable = None, to_q_v=None, to_kv_v=None, to_out_v=None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Union[ivy.Array, ivy.Container]] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: return self.static_multi_head_attention( self, scale, num_heads, context=context, mask=mask, to_q_fn=to_q_fn, to_kv_fn=to_kv_fn, to_out_fn=to_out_fn, to_q_v=to_q_v, to_kv_v=to_kv_v, to_out_v=to_out_v, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_conv1d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: int, padding: str, /, *, data_format: str = "NWC", dilations: int = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.conv1d. This method simply wraps the function, and so the docstring for ivy.conv1d also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,w, d_in]*. filters Convolution filters *[fw,d_in, d_out]*. (d_in must be the same as d from x) strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NWC" or "NCW". Defaults to "NWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> x = ivy.Container(a=ivy.array([[[2., 3., 4.], [5., 6., 7.]]]), ... b=ivy.array([[[7., 8., 9.], [10., 11., 12]]])) >>> filters = ivy.array([[[0., 0.5, 1.], [0.25, 0.5, 0.75], [-0.5, 0., 0.5 ]]]) >>> result= ivy.Container.static_conv1d(x,filters,(1,),'VALID') >>> print(result) { ... a: ivy.array([[[-1.25, 2.5, 6.25], ... [-2., 5.5, 13.]]]), ... b: ivy.array([[[-2.5, 7.5, 17.5], ... [-3.25, 10.5, 24.2]]]) } """ return ContainerBase.cont_multi_map_in_function( "conv1d", x, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def conv1d( self: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray], strides: int, padding: str, /, *, data_format: str = "NWC", dilations: int = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.conv1d. This method simply wraps the function, and so the docstring for ivy.conv1d also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,w, d_in]*. filters Convolution filters *[fw,d_in, d_out]*. (d_in must be the same as d from x) strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NWC" or "NCW". Defaults to "NWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> x = ivy.Container(a=ivy.array([[[2., 3., 4.], [5., 6., 7.]]]), ... b=ivy.array([[[7., 8., 9.], [10., 11., 12]]])) >>> filters = ivy.array([[[0., 0.5, 1.], [0.25, 0.5, 0.75], [-0.5, 0., 0.5 ]]]) >>> result= x.conv1d(filters, (1,), 'VALID') >>> print(result) { ... a: ivy.array([[[-1.25, 2.5, 6.25], ... [-2., 5.5, 13.]]]), ... b: ivy.array([[[-2.5, 7.5, 17.5], ... [-3.25, 10.5, 24.2]]]) } """ return self.static_conv1d( self, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_conv2d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, data_format: str = "NHWC", dilations: Optional[Union[int, Tuple[int], Tuple[int, int]]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.conv2d. This method simply wraps the function, and so the docstring for ivy.conv2d also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,h,w,d_in]*. filters Convolution filters *[fh,fw,d_in,d_out]*. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> x = ivy.Container(a = ivy.eye(3, 3).reshape((1, 3, 3, 1)), ... b = ivy.eye(5, 5).reshape((1, 5, 5, 1))) >>> filters = ivy.array([[2., 0., 1.], ... [1., 3., 1.], ... [0., 1., 1.]]).reshape((3, 3, 1, 1)) >>> result = ivy.Container.static_conv2d(x, filters, (2,), 'SAME') >>> print(result) { a:ivy.array([[[[4.],[0.]],[[1.],[5.]]]]), b:ivy.array([[[[4.],[0.],[0.]],[[1.],[6.],[0.]],[[0.],[1.],[5.]]]]) } """ return ContainerBase.cont_multi_map_in_function( "conv2d", x, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def conv2d( self: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, data_format: str = "NHWC", dilations: Optional[Union[int, Tuple[int], Tuple[int, int]]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of `ivy.conv2d`. This method simply wraps the function, and so the docstring for `ivy.conv2d` also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,h,w,d_in]*. filters Convolution filters *[fh,fw,d_in,d_out]*. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> x = ivy.Container(a = ivy.eye(3, 3).reshape((1, 3, 3, 1)), ... b = ivy.eye(5, 5).reshape((1, 5, 5, 1))) >>> filters = ivy.array([[2, 0, 1], ... [1, 3, 1], ... [0, 1, 1]], dtype=ivy.float32).reshape((3, 3, 1, 1)) >>> result = x.conv2d(filters, 2, 'SAME') >>> print(result) { a:ivy.array([[[[4.],[0.]],[[1.],[5.]]]]), b:ivy.array([[[[4.],[0.],[0.]],[[1.],[6.],[0.]],[[0.],[1.],[5.]]]]) } """ return self.static_conv2d( self, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_conv1d_transpose( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: int, padding: str, /, *, output_shape: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, data_format: str = "NWC", dilations: int = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Union[ivy.Array, ivy.Container]] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: return ContainerBase.cont_multi_map_in_function( "conv1d_transpose", x, filters, strides, padding, output_shape=output_shape, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def conv1d_transpose( self: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: int, padding: str, /, *, output_shape: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, data_format: str = "NWC", dilations: int = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Union[ivy.Array, ivy.Container]] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: return self.static_conv1d_transpose( self, filters, strides, padding, output_shape=output_shape, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_conv2d_transpose( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, output_shape: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, data_format: str = "NHWC", dilations: Union[int, Tuple[int], Tuple[int, int]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Union[ivy.Array, ivy.Container]] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: return ContainerBase.cont_multi_map_in_function( "conv2d_transpose", x, filters, strides, padding, output_shape=output_shape, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def conv2d_transpose( self: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int]], padding: str, /, *, output_shape: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, data_format: str = "NHWC", dilations: Union[int, Tuple[int], Tuple[int, int]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[Union[ivy.Array, ivy.Container]] = None, ) -> Union[ivy.Array, ivy.NativeArray, ivy.Container]: return self.static_conv2d_transpose( self, filters, strides, padding, output_shape=output_shape, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_depthwise_conv2d( x: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int]], padding: Union[str, List[int]], /, *, data_format: str = "NHWC", dilations: Optional[Union[int, Tuple[int], Tuple[int, int]]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.depthwise_conv2d. This method simply wraps the function, and so the docstring for ivy.depthwise_conv2d also applies to this method with minimal changes. Parameters ---------- x Input image *[batch_size,h,w,d]*. filters Convolution filters *[fh,fw,d_in]*. (d_in must be the same as d from x) strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> a = ivy.randint(0, 255, shape=(1, 128, 128, 3)).astype(ivy.float32) / 255.0 >>> b = ivy.randint(0, 255, shape=(1, 128, 128, 3)).astype(ivy.float32) / 255.0 >>> inp = ivy.Container(a=a, b=b) >>> filters = ivy.random_normal(mean=0, std=1, shape=[3, 3, 3]) >>> y = ivy.Container.static_depthwise_conv2d( ... inp, ... filters, ... strides=2, ... padding='SAME') >>> print(y.shape) [1, 64, 64, 3] """ return ContainerBase.cont_multi_map_in_function( "depthwise_conv2d", x, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def depthwise_conv2d( self: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int]], padding: Union[str, List[int]], /, *, data_format: str = "NHWC", dilations: Optional[Union[int, Tuple[int], Tuple[int, int]]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.depthwise_conv2d. This method simply wraps the function, and so the docstring for ivy.depthwise_conv2d also applies to this method with minimal changes. Parameters ---------- self Input image *[batch_size,h,w,d]*. filters Convolution filters *[fh,fw,d_in]*. (d_in must be the same as d from self) strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NHWC" or "NCHW". Defaults to "NHWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> a = ivy.randint(0, 255, shape=(1, 128, 128, 3)).astype(ivy.float32) / 255.0 >>> b = ivy.randint(0, 255, shape=(1, 128, 128, 3)).astype(ivy.float32) / 255.0 >>> inp = ivy.Container(a=a, b=b) >>> filters = ivy.random_normal(mean=0, std=1, shape=[3, 3, 3]) >>> y = inp.depthwise_conv2d(filters, 2, 'SAME') >>> print(y.shape) [1, 64, 64, 3] """ return self.static_depthwise_conv2d( self, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_conv3d( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int, int, int]], padding: str, /, *, data_format: str = "NDHWC", dilations: Optional[Union[int, Tuple[int, int, int]]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.conv3d. This method simply wraps the function, and so the docstring for ivy.conv3d also applies to this method with minimal changes. Parameters ---------- x Input volume *[batch_size,d,h,w,d_in]*. filters Convolution filters *[fdfh,fw,d_in,d_out]*. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NDHWC" or "NCDHW". Defaults to "NDHWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> x = ivy.Container(a = ivy.full((1, 2, 3, 3, 1),0.5),\ b = ivy.full((1, 2, 5, 5, 1),1.)) >>> filters = ivy.ones((3, 3, 3, 1, 1)) >>> result = ivy.Container.static_conv3d(x, filters, 2, 'SAME') >>> print(result) { a: ivy.array([[[[[4.],[4.]],[[4.],[4.]]]]]), b: ivy.array([[[[[8.],[12.],[8.]],[[12.],[18.],[12.]],[[8.],[12.],[8.]]]]]) } """ return ContainerBase.cont_multi_map_in_function( "conv3d", x, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def conv3d( self: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int, int, int]], padding: str, /, *, data_format: str = "NDHWC", dilations: Optional[Union[int, Tuple[int, int, int]]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.conv3d. This method simply wraps the function, and so the docstring for ivy.conv3d also applies to this method with minimal changes. Parameters ---------- x Input volume *[batch_size,d,h,w,d_in]*. filters Convolution filters *[fdfh,fw,d_in,d_out]*. strides The stride of the sliding window for each dimension of input. padding "SAME" or "VALID" indicating the algorithm, or list indicating the per-dimension paddings. data_format "NDHWC" or "NCDHW". Defaults to "NDHWC". dilations The dilation factor for each dimension of input. (Default value = 1) out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The result of the convolution operation. Examples -------- >>> x = ivy.Container(a = ivy.full((1, 2, 3, 3, 1),0.5),\ b = ivy.full((1, 2, 5, 5, 1),1.)) >>> filters = ivy.ones((3, 3, 3, 1, 1)) >>> result = x.conv3d(filters, 2, 'SAME') >>> print(result) { a: ivy.array([[[[[4.],[4.]],[[4.],[4.]]]]]), b: ivy.array([[[[[8.],[12.],[8.]],[[12.],[18.],[12.]],[[8.],[12.],[8.]]]]]) } """ return self.static_conv3d( self, filters, strides, padding, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_conv3d_transpose( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int]], padding: Union[str, List[int]], /, *, output_shape: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, data_format: str = "NDHWC", dilations: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "conv3d_transpose", x, filters, strides, padding, output_shape=output_shape, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def conv3d_transpose( self: ivy.Container, filters: Union[ivy.Array, ivy.NativeArray, ivy.Container], strides: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int]], padding: Union[str, List[int]], /, *, output_shape: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, data_format: str = "NDHWC", dilations: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int]] = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_conv3d_transpose( self, filters, strides, padding, output_shape=output_shape, data_format=data_format, dilations=dilations, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_lstm_update( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], init_h: Union[ivy.Array, ivy.NativeArray, ivy.Container], init_c: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[ivy.Array, ivy.NativeArray, ivy.Container], recurrent_kernel: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, bias: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, recurrent_bias: Optional[ Union[ivy.Array, ivy.NativeArray, ivy.Container] ] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> Tuple[ivy.Container, ivy.Container]: return ContainerBase.cont_multi_map_in_function( "lstm_update", x, init_h, init_c, kernel, recurrent_kernel, bias=bias, recurrent_bias=recurrent_bias, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def lstm_update( self: ivy.Container, init_h: Union[ivy.Array, ivy.NativeArray, ivy.Container], init_c: Union[ivy.Array, ivy.NativeArray, ivy.Container], kernel: Union[ivy.Array, ivy.NativeArray, ivy.Container], recurrent_kernel: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, bias: Optional[Union[ivy.Array, ivy.NativeArray, ivy.Container]] = None, recurrent_bias: Optional[ Union[ivy.Array, ivy.NativeArray, ivy.Container] ] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> Tuple[ivy.Container, ivy.Container]: return self.static_lstm_update( self, init_h, init_c, kernel, recurrent_kernel, bias=bias, recurrent_bias=recurrent_bias, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
#ivy.container.linear_algebra # global from typing import Union, Optional, Tuple, Literal, List, Dict, Sequence # local from ivy.container.base import ContainerBase import ivy inf = float("inf") # ToDo: implement all methods here as public instance methods # noinspection PyMissingConstructor,PyMethodParameters
[docs]def static_matmul( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, transpose_a: bool = False, transpose_b: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.matmul. This method simply wraps the function, and so the docstring for ivy.matul also applies to this method with minimal changes. Parameters ---------- x1 first input array x2 second input array key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret the matrix multiplication result of x1 and x2 Examples -------- >>> x = ivy.Container(a = ivy.array([[3., -1.], [-1., 3.]]) , ... b = ivy.array([[2., 1.], [1., 1.]])) >>> y = ivy.Container.static_matmul(x, x) >>> print(y) { a: ivy.array([[10., -6.], [-6., 10.]]), b: ivy.array([[5., 3.], [3., 2.]]) } """ return ContainerBase.cont_multi_map_in_function( "matmul", x1, x2, transpose_a=transpose_a, transpose_b=transpose_b, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def matmul( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, transpose_a: bool = False, transpose_b: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.matmul. This method simply wraps the function, and so the docstring for ivy.matmul also applies to this method with minimal changes. Parameters ---------- self first input array x2 second input array key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret the matrix multiplication result of self and x2 Examples -------- >>> x = ivy.Container(a = ivy.array([[3., -1.], [-1., 3.]]) , ... b = ivy.array([[2., 1.], [1., 1.]])) >>> y = x.matmul(x) >>> print(y) { a: ivy.array([[10., -6.], [-6., 10.]]), b: ivy.array([[5., 3.], [3., 2.]]) } """ return self.static_matmul( self, x2, transpose_a=transpose_a, transpose_b=transpose_b, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_cholesky( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, upper: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cholesky. This method simply wraps the function, and so the docstring for ivy.cholesky also applies to this method with minimal changes. Parameters ---------- x input array or container having shape (..., M, M) and whose innermost two dimensions form square symmetric positive-definite matrices. Should have a floating-point data type. upper If True, the result must be the upper-triangular Cholesky factor U. If False, the result must be the lower-triangular Cholesky factor L. Default: ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the Cholesky factors for each square matrix. If upper is False, the returned container must contain lower-triangular matrices; otherwise, the returned container must contain upper-triangular matrices. The returned container must have a floating-point data type determined by Type Promotion Rules and must have the same shape as self. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[3., -1.], [-1., 3.]]), ... b=ivy.array([[2., 1.], [1., 1.]])) >>> y = ivy.Container.static_cholesky(x, upper='false') >>> print(y) { a: ivy.array([[1.73, -0.577], [0., 1.63]]), b: ivy.array([[1.41, 0.707], [0., 0.707]]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[3., -1], [-1., 3.]]), ... b=ivy.array([[2., 1.], [1., 1.]])) >>> upper = ivy.Container(a=1, b=-1) >>> y = ivy.Container.static_roll(x, upper=False) >>> print(y) { a: ivy.array([[3., 3.], [-1., -1.]]), b: ivy.array([[1., 1.], [1., 2.]]) } """ return ContainerBase.cont_multi_map_in_function( "cholesky", x, upper=upper, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def cholesky( self: ivy.Container, /, *, upper: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.cholesky. This method simply wraps the function, and so the docstring for ivy.cholesky also applies to this method with minimal changes. Parameters ---------- self input container having shape (..., M, M) and whose innermost two dimensions form square symmetric positive-definite matrices. Should have a floating-point data type. upper If True, the result must be the upper-triangular Cholesky factor U. If False, the result must be the lower-triangular Cholesky factor L. Default: ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the Cholesky factors for each square matrix. If upper is False, the returned container must contain lower-triangular matrices; otherwise, the returned container must contain upper-triangular matrices. The returned container must have a floating-point data type determined by Type Promotion Rules and must have the same shape as self. Examples -------- >>> x = ivy.Container(a=ivy.array([[3., -1],[-1., 3.]]), ... b=ivy.array([[2., 1.],[1., 1.]])) >>> y = x.cholesky(upper='false') >>> print(y) { a: ivy.array([[1.73, -0.577], [0., 1.63]]), b: ivy.array([[1.41, 0.707], [0., 0.707]]) } """ return self.static_cholesky( self, upper=upper, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_cross( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: int = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cross. This method simply wraps the function, and so the docstring for ivy.cross also applies to this method with minimal changes. Parameters ---------- x1 first input array. Should have a numeric data type. x2 second input array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. axis the axis (dimension) of x1 and x2 containing the vectors for which to compute the cross product.vIf set to -1, the function computes the cross product for vectors defined by the last axis (dimension). Default: ``-1``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array containing the element-wise products. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.array([9., 0., 3.]) >>> y = ivy.Container(a=ivy.array([1., 1., 0.]), b=ivy.array([1., 0., 1.])) >>> z = ivy.Container.static_cross(x, y) >>> print(z) { a: ivy.array([-3., 3., 9.]), b: ivy.array([0., -6., 0.]) } With multiple :class:`ivy.Container` inputs: >>> x = x = ivy.Container(a=ivy.array([5., 0., 0.]), b=ivy.array([0., 0., 2.])) >>> y = ivy.Container(a=ivy.array([0., 7., 0.]), b=ivy.array([3., 0., 0.])) >>> z = ivy.Container.static_cross(x, y) >>> print(z) { a: ivy.array([0., 0., 35.]), b: ivy.array([0., 6., 0.]) } """ return ContainerBase.cont_multi_map_in_function( "cross", x1, x2, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def cross( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: int = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.cross. This method simply wraps the function, and so the docstring for ivy.cross also applies to this method with minimal changes. Parameters ---------- self first input array. Should have a numeric data type. x2 second input array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type. axis the axis (dimension) of x1 and x2 containing the vectors for which to compute (default: -1) the cross product.vIf set to -1, the function computes the cross product for vectors defined by the last axis (dimension). Default: ``-1``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array containing the element-wise products. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([5., 0., 0.]), b=ivy.array([0., 0., 2.])) >>> y = ivy.Container(a=ivy.array([0., 7., 0.]), b=ivy.array([3., 0., 0.])) >>> z = x.cross(y) >>> print(z) { a: ivy.array([0., 0., 35.]), b: ivy.array([0., 6., 0.]) } """ return self.static_cross( self, x2, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_det( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "det", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def det( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ Examples -------- >>> x = ivy.Container(a = ivy.array([[3., -1.], [-1., 3.]]) , ... b = ivy.array([[2., 1.], [1., 1.]])) >>> y = x.det() >>> print(y) {a:ivy.array(8.),b:ivy.array(1.)} """ return self.static_det( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_diagonal( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, offset: int = 0, axis1: int = -2, axis2: int = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.diagonal. This method simply wraps the function, and so the docstring for ivy.diagonal also applies to this method with minimal changes. Parameters ---------- x input Container with leave arrays having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. offset offset specifying the off-diagonal relative to the main diagonal. - ``offset = 0``: the main diagonal. - ``offset > 0``: off-diagonal above the main diagonal. - ``offset < 0``: off-diagonal below the main diagonal. Default: `0`. axis1 axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to first axis (-2). axis2 axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to second axis (-1). out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the diagonals. More details can be found in the docstring for ivy.diagonal. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[1., 2.], [3., 4.]], ... b=ivy.array([[5., 6.], [7., 8.]]))) >>> d = ivy.Container.static_diagonal(x) >>> print(d) { a:ivy.array([1., 4.]), b:ivy.array([5., 8.]) } >>> a = ivy.array([[0, 1, 2], ... [3, 4, 5], ... [6, 7, 8]]) >>> b = ivy.array([[-1., -2., -3.], ... [-3., 4., 5.], ... [5., 6., 7.]])], >>> x = ivy.Container(a=a, b=b) >>> d = ivy.Container.static_diagonal(offset=-1, axis1=0) >>> print(d) { a:ivy.array([3., 7.]), b:ivy.array([-3., 6.]) } """ return ContainerBase.cont_multi_map_in_function( "diagonal", x, offset=offset, axis1=axis1, axis2=axis2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def diagonal( self: ivy.Container, /, *, offset: int = 0, axis1: int = -2, axis2: int = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.diagonal. This method simply wraps the function, and so the docstring for ivy.diagonal also applies to this method with minimal changes. Parameters ---------- self input Container with leave arrays having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. offset offset specifying the off-diagonal relative to the main diagonal. - ``offset = 0``: the main diagonal. - ``offset > 0``: off-diagonal above the main diagonal. - ``offset < 0``: off-diagonal below the main diagonal. Default: `0`. axis1 axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to first axis (-2). axis2 axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to second axis (-1). out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the diagonals. More details can be found in the docstring for ivy.diagonal. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[1., 2.], [3., 4.]]), ... b=ivy.array([[5., 6.], [7., 8.]])) >>> d = x.diagonal() >>> print(d) { a:ivy.array([1., 4.]), b:ivy.array([5., 8.]) } >>> a = ivy.array([[0, 1, 2], ... [3, 4, 5], ... [6, 7, 8]]) >>> b = ivy.array([[-1., -2., -3.], ... [-3., 4., 5.], ... [5., 6., 7.]])], >>> x = ivy.Container(a=a, b=b) >>> d = x.diagonal(offset=-1, axis1=0) >>> print(d) { a:ivy.array([3., 7.]), b:ivy.array([-3., 6.]) } """ return self.static_diagonal( self, offset=offset, axis1=axis1, axis2=axis2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_diag( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, k: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "diag", x, k=k, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def diag( self: ivy.Container, /, *, k: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.diag. This method simply wraps the function, and so the docstring for ivy.diag also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=[[0, 1, 2], >>> [3, 4, 5], >>> [6, 7, 8]]) >>> ivy.diag(x, k=1) { a: ivy.array([1, 5]) } """ return self.static_diag( self, k=k, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_eigh( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, UPLO: Optional[str] = "L", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "eigh", x, UPLO=UPLO, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def eigh( self: ivy.Container, /, *, UPLO: Optional[str] = "L", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_eigh( self, UPLO=UPLO, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_eigvalsh( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, UPLO: Optional[str] = "L", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.eigvalsh. This method simply wraps the function, and so the docstring for ivy.eigvalsh also applies to this method with minimal changes. Parameters ---------- x Ivy container having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the computed eigenvalues. The returned array must have shape (..., M) and have the same data type as x. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[[1.,2.,3.],[2.,4.,5.],[3.,5.,6.]]]), ... b=ivy.array([[[1.,1.,2.],[1.,2.,1.],[2.,1.,1.]]]), ... c=ivy.array([[[2.,2.,2.],[2.,3.,3.],[2.,3.,3.]]])) >>> e = ivy.Container.static_eigvalsh(x) >>> print(e) { a: ivy.array([[-0.51572949, 0.17091519, 11.3448143]]), b: ivy.array([[-1., 1., 4.]]), c: ivy.array([[-8.88178420e-16, 5.35898387e-01, 7.46410179e+00]]) } """ return ContainerBase.cont_multi_map_in_function( "eigvalsh", x, UPLO=UPLO, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def eigvalsh( self: ivy.Container, /, *, UPLO: Optional[str] = "L", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.eigvalsh. This method simply wraps the function, and so the docstring for ivy.eigvalsh also applies to this method with minimal changes. Parameters ---------- self Ivy container having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the computed eigenvalues. The returned array must have shape (..., M) and have the same data type as x. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[[1.,2.],[2.,1.]]]), ... b=ivy.array([[[2.,4.],[4.,2.]]])) >>> y = ivy.eigvalsh(x) >>> print(y) { a: ivy.array([[-1., 3.]]), b: ivy.array([[-2., 6.]]) } """ return self.static_eigvalsh( self, UPLO=UPLO, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_inner( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "inner", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def inner( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_inner( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_inv( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, adjoint: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.inv. This method simply wraps the function, and so the docstring for ivy.inv also applies to this method with minimal changes. Parameters ---------- x Ivy container having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container containing the multiplicative inverses. The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have the same shape as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[0., 1.], [4., 4.]]), ... b=ivy.array([[4., 4.], [2., 1.]])) >>> y = ivy.Container.static_inv(x) >>> print(y) { a: ivy.array([[-1, 0.25], [1., 0.]]), b: ivy.array([-0.25, 1.], [0.5, -1.]) } """ return ContainerBase.cont_multi_map_in_function( "inv", x, adjoint=adjoint, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def inv( self: ivy.Container, /, *, adjoint: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.inv. This method simply wraps the function, and so the docstring for ivy.inv also applies to this method with minimal changes. Parameters ---------- self Ivy container having shape ``(..., M, M)`` and whose innermost two dimensions form square matrices. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container containing the multiplicative inverses. The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have the same shape as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[0., 1.], [4., 4.]]), ... b=ivy.array([[4., 4.], [2., 1.]])) >>> y = x.inv() >>> print(y) { a: ivy.array([[-1, 0.25], [1., 0.]]), b: ivy.array([-0.25, 1.], [0.5, -1.]) } """ return self.static_inv( self, adjoint=adjoint, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_pinv( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, rtol: Optional[Union[float, Tuple[float]]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container special method variant of ivy.pinv. This method simply wraps the function, and so the docstring for ivy.pinv also applies to this method with minimal changes. Parameters ---------- x input array having shape ``(..., M, N)`` and whose innermost two dimensions form``MxN`` matrices. Should have a floating-point data type. rtol relative tolerance for small singular values approximately less than or equal to ``rtol * largest_singular_value`` are set to zero. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array containing the pseudo-inverses. The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have shape ``(..., N, M)`` (i.e., must have the same shape as ``x``, except the innermost two dimensions must be transposed). Examples -------- >>> x = ivy.Container(a= ivy.array([[1., 2.], [3., 4.]])) >>> y = ivy.Container.static_pinv(x) >>> print(y) { a: ivy.array([[-2., 1.], [1.5, -0.5]]) } >>> x = ivy.Container(a=ivy.array([[1., 2.], [3., 4.]])) >>> out = ivy.Container(a=ivy.zeros((2, 2))) >>> ivy.Container.static_pinv(x, rtol=1e-1, out=out) >>> print(out) { a: ivy.array([[0.0426, 0.0964], [0.0605, 0.1368]]) } """ return ContainerBase.cont_multi_map_in_function( "pinv", x, rtol=rtol, out=out, )
[docs]def pinv( self: ivy.Container, /, *, rtol: Optional[Union[float, Tuple[float]]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.pinv. This method simply wraps the function, and so the docstring for ivy.pinv also applies to this method with minimal changes. Parameters ---------- x input array having shape ``(..., M, N)`` and whose innermost two dimensions form``MxN`` matrices. Should have a floating-point data type. rtol relative tolerance for small singular values approximately less than or equal to ``rtol * largest_singular_value`` are set to zero. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array containing the pseudo-inverses. The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have shape ``(..., N, M)`` (i.e., must have the same shape as ``x``, except the innermost two dimensions must be transposed). Examples -------- >>> x = ivy.Container(a= ivy.array([[1., 2.], [3., 4.]])) >>> y = x.pinv() >>> print(y) { a: ivy.array([[-2., 1.], [1.5, -0.5]]) } >>> x = ivy.Container(a=ivy.array([[1., 2.], [3., 4.]])) >>> out = ivy.Container(a=ivy.zeros_like(x[a])) >>> x.pinv(0., out=out) >>> print(out) { a: ivy.array([[-1.99999988, 1.], [1.5, -0.5]]) } """ return self.static_pinv( self, rtol=rtol, out=out, )
[docs]def static_matrix_norm( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, ord: Optional[Union[int, float, Literal[inf, -inf, "fro", "nuc"]]] = "fro", axis: Optional[Tuple[int, int]] = (-2, -1), keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.matrix_norm. This method simply wraps the function, and so the docstring for ivy.matrix_norm also applies to this method with minimal changes. Parameters ---------- x Input array having shape (..., M, N) and whose innermost two deimensions form MxN matrices. Should have a floating-point data type. ord Order of the norm. Default is "fro". axis specifies the axes that hold 2-D matrices. Default: (-2, -1). keepdims If this is set to True, the axes which are normed over are left in the result as dimensions with size one. With this option the result will broadcast correctly against the original x. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Matrix norm of the array at specified axes. Examples -------- >>> x = ivy.Container(a=ivy.array([[1.1, 2.2], [1., 2.]]), \ b=ivy.array([[1., 2.], [3., 4.]])) >>> y = ivy.Container.static_matrix_norm(x, ord=1) >>> print(y) { a: ivy.array(4.2), b: ivy.array(6.) } >>> x = ivy.Container(a=ivy.arange(12, dtype=float).reshape((3, 2, 2)), \ b=ivy.arange(8, dtype=float).reshape((2, 2, 2))) >>> ord = ivy.Container(a=1, b=float('inf')) >>> axis = ivy.Container(a=(1, 2), b=(2, 1)) >>> k = ivy.Container(a=False, b=True) >>> y = ivy.Container.static_matrix_norm(x, ord=ord, axis=axis, keepdims=k) >>> print(y) { a: ivy.array([4.24, 11.4, 19.2]), b: ivy.array([[[3.7]], [[11.2]]]) } """ return ContainerBase.cont_multi_map_in_function( "matrix_norm", x, ord=ord, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def matrix_norm( self: ivy.Container, /, *, ord: Optional[Union[int, float, Literal[inf, -inf, "fro", "nuc"]]] = "fro", axis: Optional[Tuple[int, int]] = (-2, -1), keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.matrix_norm. This method simply wraps the function, and so the docstring for ivy.matrix_norm also applies to this method with minimal changes. Parameters ---------- self Container having shape (..., M, N) and whose innermost two dimensions form MxN matrices. Should have a floating-point data type. ord Order of the norm. Default is "fro". axis specifies the axes that hold 2-D matrices. Default: (-2, -1). keepdims If this is set to True, the axes which are normed over are left in the result as dimensions with size one. With this option the result will broadcast correctly against the original x. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Matrix norm of the array at specified axes. Examples -------- >>> x = ivy.Container(a=ivy.array([[1.1, 2.2], [1., 2.]]), \ b=ivy.array([[1., 2.], [3., 4.]])) >>> y = x.matrix_norm(ord=1) >>> print(y) { a: ivy.array(4.2), b: ivy.array(6.) } >>> x = ivy.Container(a=ivy.arange(12, dtype=float).reshape((3, 2, 2)), \ b=ivy.arange(8, dtype=float).reshape((2, 2, 2))) >>> ord = ivy.Container(a="nuc", b=ivy.inf) >>> axis = ivy.Container(a=(1, 2), b=(2, 1)) >>> k = ivy.Container(a=True, b=False) >>> y = x.matrix_norm(ord=ord, axis=axis, keepdims=k) >>> print(y) { a: ivy.array([[[4.24]], [[11.4]], [[19.2]]]), b: ivy.array([4., 12.]) } """ return self.static_matrix_norm( self, ord=ord, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_matrix_power( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], n: int, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "matrix_power", x, n, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def matrix_power( self: ivy.Container, n: int, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_matrix_power( self, n, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_matrix_rank( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, atol: Optional[Union[float, Tuple[float]]] = None, rtol: Optional[Union[float, Tuple[float]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.matrix_rank. This method returns the rank (i.e., number of non-zero singular values) of a matrix (or a stack of matrices). Parameters ---------- x input array or container having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. Should have a floating-point data type. atol absolute tolerance. When None it’s considered to be zero. rtol relative tolerance for small singular values. Singular values approximately less than or equal to ``rtol * largest_singular_value`` are set to zero. If a ``float``, the value is equivalent to a zero-dimensional array having a floating-point data type determined by :ref:`type-promotion` (as applied to ``x``) and must be broadcast against each matrix. If an ``array``, must have a floating-point data type and must be compatible with ``shape(x)[:-2]`` (see:ref:`broadcasting`). If ``None``, the default value is ``max(M, N) * eps``, where ``eps`` must be the machine epsilon associated with the floating-point data type determined by :ref:`type-promotion` (as applied to ``x``). Default: ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the ranks. The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have shape ``(...)`` (i.e., must have a shape equal to ``shape(x)[:-2]``). Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[1., 0.], [0., 1.]]), ... b=ivy.array([[1., 0.], [0., 0.]])) >>> y = ivy.Container.static_matrix_rank(x) >>> print(y) { a: ivy.array(2.), b: ivy.array(1.) } """ return ContainerBase.cont_multi_map_in_function( "matrix_rank", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, atol=atol, rtol=rtol, out=out, )
[docs]def matrix_rank( self: ivy.Container, /, *, atol: Optional[Union[float, Tuple[float]]] = None, rtol: Optional[Union[float, Tuple[float]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.matrix_rank. This method returns the rank (i.e., number of non-zero singular values) of a matrix (or a stack of matrices). Parameters ---------- self input container having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. Should have a floating-point data type. atol absolute tolerance. When None it’s considered to be zero. rtol relative tolerance for small singular values. Singular values approximately less than or equal to ``rtol * largest_singular_value`` are set to zero. If a ``float``, the value is equivalent to a zero-dimensional array having a floating-point data type determined by :ref:`type-promotion` (as applied to ``x``) and must be broadcast against each matrix. If an ``array``, must have a floating-point data type and must be compatible with ``shape(x)[:-2]`` (see :ref:`broadcasting`). If ``None``, the default value is ``max(M, N) * eps``, where ``eps`` must be the machine epsilon associated with the floating-point data type determined by :ref:`type-promotion` (as applied to ``x``). Default: ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the ranks. The returned array must have a floating-point data type determined by :ref:`type-promotion` and must have shape ``(...)`` (i.e., must have a shape equal to ``shape(x)[:-2]``). Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[1., 0.], [0., 1.]]), ... b=ivy.array([[1., 0.], [0., 0.]])) >>> y = x.matrix_rank() >>> print(y) { a: ivy.array(2), b: ivy.array(1) } """ return self.static_matrix_rank( self, atol=atol, rtol=rtol, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_matrix_transpose( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ Transposes a matrix (or a stack of matrices) ``x``. Parameters ---------- x input Container which will have arrays with shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the transposes for each matrix and having shape ``(..., N, M)``. The returned array must have the same data type as ``x``. Examples -------- With :code:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([[1., 1.], [0., 3.]]), \ b=ivy.array([[0., 4.], [3., 1.]])) >>> y = ivy.Container.static_matrix_transpose(x) >>> print(y) { a: ivy.array([[1., 0.], [1., 3.]]), b: ivy.array([[0., 3.], [4., 1.]]) } """ return ContainerBase.cont_multi_map_in_function( "matrix_transpose", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def matrix_transpose( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ Transposes a matrix (or a stack of matrices) ``x``. Parameters ---------- self input Container which will have arrays with shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the transposes for each matrix and having shape ``(..., N, M)``. The returned array must have the same data type as ``x``. Examples -------- With :code:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([[1., 1.], [0., 3.]]), \ b=ivy.array([[0., 4.], [3., 1.]])) >>> y = x.matrix_transpose() >>> print(y) { a: ivy.array([[1., 0.], [1., 3.]]), b: ivy.array([[0., 3.], [4., 1.]]) } """ return self.static_matrix_transpose( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_outer( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "outer", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def outer( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_outer( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_qr( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, mode: str = "reduced", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "qr", x, mode=mode, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def qr( self: ivy.Container, /, *, mode: str = "reduced", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_qr( self, mode=mode, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_slogdet( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.slogdet. This method simply wraps the function, and so the docstring for ivy.slogdet also applies to this method with minimal changes. Parameters ---------- x input array or container having shape (..., M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret This function returns a container containing NamedTuples. Each NamedTuple of output will have - sign: An array containing a number representing the sign of the determinant for each square matrix. logabsdet: An array containing natural log of the absolute determinant of each square matrix. Examples -------- >>> x = ivy.Container(a=ivy.array([[1.0, 2.0], ... [3.0, 4.0]]), ... b=ivy.array([[1.0, 2.0], ... [2.0, 1.0]])) >>> y = ivy.Container.static_slogdet(x) >>> print(y) { a: [ sign = ivy.array(-1.), logabsdet = ivy.array(0.6931472) ], b: [ sign = ivy.array(-1.), logabsdet = ivy.array(1.0986123) ] } """ return ContainerBase.cont_multi_map_in_function( "slogdet", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def slogdet( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.slogdet. This method simply wraps the function, and so the docstring for ivy.slogdet also applies to this method with minimal changes. Parameters ---------- self input container having shape (..., M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret This function returns container containing NamedTuples. Each NamedTuple of output will have - sign: An array of a number representing the sign of the determinant of each square. logabsdet: An array of the natural log of the absolute value of the determinant of each square. Examples -------- >>> x = ivy.Container(a=ivy.array([[1.0, 2.0], ... [3.0, 4.0]]), ... b=ivy.array([[1.0, 2.0], ... [2.0, 1.0]])) >>> y = x.slogdet() >>> print(y) { a: [ sign = ivy.array(-1.), logabsdet = ivy.array(0.6931472) ], b: [ sign = ivy.array(-1.), logabsdet = ivy.array(1.0986123) ] } """ return self.static_slogdet( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_solve( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "solve", x1, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def solve( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_solve( self, x2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_svd( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, compute_uv: bool = True, full_matrices: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> Union[ivy.Container, Tuple[ivy.Container, ...]]: """ivy.Container static method variant of ivy.svd. This method simply wraps the function, and so the docstring for ivy.svd also applies to this method with minimal changes. Parameters ---------- x input container with array leaves having shape ``(..., M, N)`` and whose innermost two dimensions form matrices on which to perform singular value decomposition. Should have a floating-point data type. full_matrices If ``True``, compute full-sized ``U`` and ``Vh``, such that ``U`` has shape ``(..., M, M)`` and ``Vh`` has shape ``(..., N, N)``. If ``False``, compute on the leading ``K`` singular vectors, such that ``U`` has shape ``(..., M, K)`` and ``Vh`` has shape ``(..., K, N)`` and where ``K = min(M, N)``. Default: ``True``. compute_uv If ``True`` then left and right singular vectors will be computed and returned in ``U`` and ``Vh``, respectively. Otherwise, only the singular values will be computed, which can be significantly faster. .. note:: with backend set as torch, svd with still compute left and right singular vectors irrespective of the value of compute_uv, however Ivy will still only return the singular values. Returns ------- .. note:: once complex numbers are supported, each square matrix must be Hermitian. ret A container of a namedtuples ``(U, S, Vh)``. More details in ivy.svd. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.random_normal(shape = (9, 6)) >>> y = ivy.random_normal(shape = (2, 4)) >>> z = ivy.Container(a=x, b=y) >>> ret = ivy.Container.static_svd(z) >>> aU, aS, aVh = ret.a >>> bU, bS, bVh = ret.b >>> print(aU.shape, aS.shape, aVh.shape, bU.shape, bS.shape, bVh.shape) (9, 9) (6,) (6, 6) (2, 2) (2,) (4, 4) """ return ContainerBase.cont_multi_map_in_function( "svd", x, compute_uv=compute_uv, full_matrices=full_matrices, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def svd( self: ivy.Container, /, *, compute_uv: bool = True, full_matrices: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.svd. This method simply wraps the function, and so the docstring for ivy.svd also applies to this method with minimal changes. Parameters ---------- self input container with array leaves having shape ``(..., M, N)`` and whose innermost two dimensions form matrices on which to perform singular value decomposition. Should have a floating-point data type. full_matrices If ``True``, compute full-sized ``U`` and ``Vh``, such that ``U`` has shape ``(..., M, M)`` and ``Vh`` has shape ``(..., N, N)``. If ``False``, compute on the leading ``K`` singular vectors, such that ``U`` has shape ``(..., M, K)`` and ``Vh`` has shape ``(..., K, N)`` and where ``K = min(M, N)``. Default: ``True``. compute_uv If ``True`` then left and right singular vectors will be computed and returned in ``U`` and ``Vh``, respectively. Otherwise, only the singular values will be computed, which can be significantly faster. .. note:: with backend set as torch, svd with still compute left and right singular vectors irrespective of the value of compute_uv, however Ivy will still only return the singular values. Returns ------- .. note:: once complex numbers are supported, each square matrix must be Hermitian. ret A container of a namedtuples ``(U, S, Vh)``. More details in ivy.svd. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.random_normal(shape = (9, 6)) >>> y = ivy.random_normal(shape = (2, 4)) >>> z = ivy.Container(a=x, b=y) >>> ret = z.svd() >>> aU, aS, aVh = ret.a >>> bU, bS, bVh = ret.b >>> print(aU.shape, aS.shape, aVh.shape, bU.shape, bS.shape, bVh.shape) (9, 9) (6,) (6, 6) (2, 2) (2,) (4, 4) """ return self.static_svd( self, compute_uv=compute_uv, full_matrices=full_matrices, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_svdvals( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "svdvals", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def svdvals( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_svdvals( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_tensordot( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], x2: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axes: Union[int, Tuple[List[int], List[int]]] = 2, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "tensordot", x1, x2, axes=axes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def tensordot( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axes: Union[int, Tuple[List[int], List[int]]] = 2, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_tensordot( self, x2, axes=axes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def tensorsolve( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axes: Union[int, Tuple[List[int], List[int]]] = None, ) -> ivy.Container: return self.tensorsolve( self, x2, axes=axes, )
[docs]def static_trace( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, offset: int = 0, axis1: int = 0, axis2: int = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.trace. This method Returns the sum along the specified diagonals of a matrix (or a stack of matrices). Parameters ---------- x input container having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. Should have a floating-point data type. offset Offset of the diagonal from the main diagonal. Can be both positive and negative. Defaults to 0. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the traces and whose shape is determined by removing the last two dimensions and storing the traces in the last array dimension. For example, if ``x`` has rank ``k`` and shape ``(I, J, K, ..., L, M, N)``, then an output array has rank ``k-2`` and shape ``(I, J, K, ..., L)`` where :: out[i, j, k, ..., l] = trace(a[i, j, k, ..., l, :, :]) The returned array must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container( ... a = ivy.array([[7, 1, 2], ... [1, 3, 5], ... [0, 7, 4]]), ... b = ivy.array([[4, 3, 2], ... [1, 9, 5], ... [7, 0, 6]]) ) >>> y = x.Container.static_trace(x) >>> print(y) { a: ivy.array(14), b: ivy.array(19) } """ return ContainerBase.cont_multi_map_in_function( "trace", x, offset=offset, axis1=axis1, axis2=axis2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def trace( self: ivy.Container, /, *, offset: int = 0, axis1: int = 0, axis2: int = 1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.trace. This method Returns the sum along the specified diagonals of a matrix (or a stack of matrices). Parameters ---------- self input container having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices. Should have a floating-point data type. offset Offset of the diagonal from the main diagonal. Can be both positive and negative. Defaults to 0. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the traces and whose shape is determined by removing the last two dimensions and storing the traces in the last array dimension. For example, if ``x`` has rank ``k`` and shape ``(I, J, K, ..., L, M, N)``, then an output array has rank ``k-2`` and shape ``(I, J, K, ..., L)`` where :: out[i, j, k, ..., l] = trace(a[i, j, k, ..., l, :, :]) The returned array must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container( ... a = ivy.array([[7, 1, 2], ... [1, 3, 5], ... [0, 7, 4]]), ... b = ivy.array([[4, 3, 2], ... [1, 9, 5], ... [7, 0, 6]])) >>> y = x.trace() >>> print(y) { a: ivy.array(14), b: ivy.array(19) } """ return self.static_trace( self, offset=offset, axis1=axis1, axis2=axis2, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_vecdot( x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: int = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "vecdot", x1, x2, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def vecdot( self: ivy.Container, x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: int = -1, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_vecdot( self, x2, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_vector_norm( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: Optional[Union[int, Sequence[int]]] = None, keepdims: Optional[bool] = False, ord: Optional[Union[int, float, Literal[inf, -inf]]] = 2, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.vector_norm. This method simply wraps the function, and so the docstring for ivy.vector_norm also applies to this method with minimal changes. Parameters ---------- x input array. Should have a floating-point data type. axis If an integer, ``axis`` specifies the axis (dimension) along which to compute vector norms. If an n-tuple, ``axis`` specifies the axes (dimensions) along which to compute batched vector norms. If ``None``, the vector norm must be computed over all array values (i.e., equivalent to computing the vector norm of a flattened array). Negative indices must be supported. Default: ``None``. keepdims If ``True``, the axes (dimensions) specified by ``axis`` must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the axes (dimensions) specified by ``axis`` must not be included in the result. Default: ``False``. ord order of the norm. The following mathematical norms must be supported: +------------------+----------------------------+ | ord | description | +==================+============================+ | 1 | L1-norm (Manhattan) | +------------------+----------------------------+ | 2 | L2-norm (Euclidean) | +------------------+----------------------------+ | inf | infinity norm | +------------------+----------------------------+ | (int,float >= 1) | p-norm | +------------------+----------------------------+ The following non-mathematical "norms" must be supported: +------------------+--------------------------------+ | ord | description | +==================+================================+ | 0 | sum(a != 0) | +------------------+--------------------------------+ | -1 | 1./sum(1./abs(a)) | +------------------+--------------------------------+ | -2 | 1./sqrt(sum(1./abs(a)/*/*2)) | +------------------+--------------------------------+ | -inf | min(abs(a)) | +------------------+--------------------------------+ | (int,float < 1) | sum(abs(a)/*/*ord)/*/*(1./ord) | +------------------+--------------------------------+ Default: ``2``. dtype data type that may be used to perform the computation more precisely. The input array ``x`` gets cast to ``dtype`` before the function's computations. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array containing the vector norms. If ``axis`` is ``None``, the returned array must be a zero-dimensional array containing a vector norm. If ``axis`` is a scalar value (``int`` or ``float``), the returned array must have a rank which is one less than the rank of ``x``. If ``axis`` is a ``n``-tuple, the returned array must have a rank which is ``n`` less than the rank of ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`. """ return ContainerBase.cont_multi_map_in_function( "vector_norm", x, axis=axis, keepdims=keepdims, ord=ord, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def vector_norm( self: ivy.Container, /, *, axis: Optional[Union[int, Sequence[int]]] = None, keepdims: Optional[bool] = False, ord: Optional[Union[int, float, Literal[inf, -inf]]] = 2, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: r""" ivy.Container instance method variant of ivy.vector_norm. This method simply wraps the function, and so the docstring for ivy.vector_norm also applies to this method with minimal changes. Parameters ---------- self input array. Should have a floating-point data type. axis If an integer, ``axis`` specifies the axis (dimension) along which to compute vector norms. If an n-tuple, ``axis`` specifies the axes (dimensions) along which to compute batched vector norms. If ``None``, the vector norm must be computed over all array values (i.e., equivalent to computing the vector norm of a flattened array). Negative indices must be supported. Default: ``None``. keepdims If ``True``, the axes (dimensions) specified by ``axis`` must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`).Otherwise, if ``False``, the axes (dimensions) specified by ``axis`` must not be included in the result. Default: ``False``. ord order of the norm. The following mathematical norms must be supported: +------------------+----------------------------+ | ord | description | +==================+============================+ | 1 | L1-norm (Manhattan) | +------------------+----------------------------+ | 2 | L2-norm (Euclidean) | +------------------+----------------------------+ | inf | infinity norm | +------------------+----------------------------+ | (int,float >= 1) | p-norm | +------------------+----------------------------+ The following non-mathematical "norms" must be supported: +------------------+--------------------------------+ | ord | description | +==================+================================+ | 0 | sum(a != 0) | +------------------+--------------------------------+ | -1 | 1./sum(1./abs(a)) | +------------------+--------------------------------+ | -2 | 1./sqrt(sum(1./abs(a)/*/*2)) | +------------------+--------------------------------+ | -inf | min(abs(a)) | +------------------+--------------------------------+ | (int,float < 1) | sum(abs(a)/*/*ord)/*/*(1./ord) | +------------------+--------------------------------+ Default: ``2``. dtype data type that may be used to perform the computation more precisely. The input array ``x`` gets cast to ``dtype`` before the function's computations. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an array containing the vector norms. If ``axis`` is ``None``, the returned array must be a zero-dimensional array containing a vector norm. If ``axis`` is a scalar value (``int`` or ``float``), the returned array must have a rank which is one less than the rank of ``x``. If ``axis`` is a ``n``-tuple, the returned array must have a rank which is ``n`` less than the rank of ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`. """ return self.static_vector_norm( self, axis=axis, keepdims=keepdims, ord=ord, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_vector_to_skew_symmetric_matrix( vector: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "vector_to_skew_symmetric_matrix", vector, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def vector_to_skew_symmetric_matrix( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_vector_to_skew_symmetric_matrix( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_vander( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, N: Optional[int] = None, increasing: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.vander. This method simply wraps the function, and so the docstring for ivy.vander also applies to this method with minimal changes. Parameters ---------- x ivy container that contains 1-D arrays. N Number of columns in the output. If N is not specified, a square array is returned (N = len(x)) increasing Order of the powers of the columns. If True, the powers increase from left to right, if False (the default) they are reversed. out optional output container, for writing the result to. Returns ------- ret container that contains the Vandermonde matrix of the arrays included in the input container. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container( a = ivy.array([1, 2, 3, 5]) b = ivy.array([6, 7, 8, 9]) ) >>> ivy.Container.static_vander(x) { a: ivy.array( [[ 1, 1, 1, 1], [ 8, 4, 2, 1], [ 27, 9, 3, 1], [125, 25, 5, 1]] ), b: ivy.array( [[216, 36, 6, 1], [343, 49, 7, 1], [512, 64, 8, 1], [729, 81, 9, 1]] ) } """ return ContainerBase.cont_multi_map_in_function( "vander", x, N=N, increasing=increasing, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def vander( self: ivy.Container, /, *, N: Optional[int] = None, increasing: Optional[bool] = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.vander. This method Returns the Vandermonde matrix of the input array. Parameters ---------- self 1-D input array. N Number of columns in the output. If N is not specified, a square array is returned (N = len(x)) increasing Order of the powers of the columns. If True, the powers increase from left to right, if False (the default) they are reversed. out optional output container, for writing the result to. Returns ------- ret an container containing the Vandermonde matrices of the arrays included in the input container. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container( a = ivy.array([1, 2, 3, 5]) b = ivy.array([6, 7, 8, 9]) ) >>> x.vander() { a: ivy.array( [[ 1, 1, 1, 1], [ 8, 4, 2, 1], [ 27, 9, 3, 1], [125, 25, 5, 1]] ), b: ivy.array( [[216, 36, 6, 1], [343, 49, 7, 1], [512, 64, 8, 1], [729, 81, 9, 1]] ) } """ return self.static_vander( self, N=N, increasing=increasing, out=out, )
#ivy.container.losses # global from typing import Optional, Union, List, Dict # local import ivy from ivy.container.base import ContainerBase
[docs]def static_cross_entropy( true: Union[ivy.Container, ivy.Array, ivy.NativeArray], pred: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Union[int, ivy.Container] = -1, epsilon: Union[float, ivy.Container] = 1e-7, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cross_entropy. This method simply wraps the function, and so the docstring for ivy.cross_entropy also applies to this method with minimal changes. Parameters ---------- true input array or container containing true labels. pred input array or container containing the predicted labels. axis the axis along which to compute the cross-entropy. If axis is ``-1``, the cross-entropy will be computed along the last dimension. Default: ``-1``. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The cross-entropy loss between the given distributions. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0, 0, 1]), b=ivy.array([1, 1, 0])) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> z = ivy.Container.static_cross_entropy(x, y) >>> print(z) { a: ivy.array(1.20397282), b: ivy.array(1.83258148) } With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs: >>> x = ivy.array([0, 0, 1]) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> z = ivy.Container.static_cross_entropy(x, y) >>> print(z) { a: ivy.array(1.20397282), b: ivy.array(1.60943794) } """ return ContainerBase.cont_multi_map_in_function( "cross_entropy", true, pred, axis=axis, epsilon=epsilon, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def cross_entropy( self: ivy.Container, pred: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Union[int, ivy.Container] = -1, epsilon: Union[float, ivy.Container] = 1e-7, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.cross_entropy. This method simply wraps the function, and so the docstring for ivy.cross_entropy also applies to this method with minimal changes. Parameters ---------- self input container containing true labels. pred input array or container containing the predicted labels. axis the axis along which to compute the cross-entropy. If axis is ``-1``, the cross-entropy will be computed along the last dimension. Default: ``-1``. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The cross-entropy loss between the given distributions. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 0, 0]),b=ivy.array([0, 0, 1])) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> z = x.cross_entropy(y) >>> print(z) { a:ivy.array(0.5108256), b:ivy.array(1.609438) } """ return self.static_cross_entropy( self, pred, axis=axis, epsilon=epsilon, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_binary_cross_entropy( true: Union[ivy.Container, ivy.Array, ivy.NativeArray], pred: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, epsilon: Union[float, ivy.Container] = 1e-7, reduction: str = "none", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.binary_cross_entropy. This method simply wraps the function, and so the docstring for ivy.binary_cross_entropy also applies to this method with minimal changes. Parameters ---------- true input array or container containing true labels. pred input array or container containing Predicted labels. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The binary cross entropy between the given distributions. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 0, 0]),b=ivy.array([0, 0, 1])) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> z = ivy.Container.static_binary_cross_entropy(x, y) >>> print(z) { a: ivy.array([0.511, 0.223, 0.357]), b: ivy.array([1.61, 0.223, 1.61]) } With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs: >>> x = ivy.array([1 , 1, 0]) >>> y = ivy.Container(a=ivy.array([0.7, 0.8, 0.2]),b=ivy.array([0.2, 0.6, 0.7])) >>> z = ivy.Container.static_binary_cross_entropy(x, y) >>> print(z) { a: ivy.array([0.357, 0.223, 0.223]), b: ivy.array([1.61, 0.511, 1.2]) } """ return ContainerBase.cont_multi_map_in_function( "binary_cross_entropy", true, pred, epsilon=epsilon, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def binary_cross_entropy( self: ivy.Container, pred: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, epsilon: Union[float, ivy.Container] = 1e-7, reduction: str = "none", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.binary_cross_entropy. This method simply wraps the function, and so the docstring for ivy.binary_cross_entropy also applies to this method with minimal changes. Parameters ---------- self input container containing true labels. pred input array or container containing Predicted labels. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The binary cross entropy between the given distributions. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 0, 0]),b=ivy.array([0, 0, 1])) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> z = x.binary_cross_entropy(y) >>> print(z) { a: ivy.array([0.511, 0.223, 0.357]), b: ivy.array([1.61, 0.223, 1.61]) } """ return self.static_binary_cross_entropy( self, pred, epsilon=epsilon, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sparse_cross_entropy( true: Union[ivy.Container, ivy.Array, ivy.NativeArray], pred: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Union[int, ivy.Container] = -1, epsilon: Union[float, ivy.Container] = 1e-7, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sparse_cross_entropy. This method simply wraps the function, and so the docstring for ivy.sparse_cross_entropy also applies to this method with minimal changes. Parameters ---------- true input array or container containing the true labels as logits. pred input array or container containing the predicted labels as logits. axis the axis along which to compute the cross-entropy. If axis is ``-1``, the cross-entropy will be computed along the last dimension. Default: ``-1``. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The sparse cross-entropy loss between the given distributions. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([1, 0, 0]),b=ivy.array([0, 0, 1])) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> z = ivy.Container.static_sparse_cross_entropy(x, y) >>> print(z) { a: ivy.array([1.61, 0.511, 0.511]), b: ivy.array([0.223, 0.223, 1.61]) } With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs: >>> x = ivy.array([1 , 1, 0]) >>> y = ivy.Container(a=ivy.array([0.7, 0.8, 0.2]),b=ivy.array([0.2, 0.6, 0.7])) >>> z = ivy.Container.static_sparse_cross_entropy(x, y) >>> print(z) { a: ivy.array([0.223, 0.223, 0.357]), b: ivy.array([0.511, 0.511, 1.61]) } """ return ContainerBase.cont_multi_map_in_function( "sparse_cross_entropy", true, pred, axis=axis, epsilon=epsilon, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sparse_cross_entropy( self: ivy.Container, pred: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Union[int, ivy.Container] = -1, epsilon: Union[float, ivy.Container] = 1e-7, reduction: str = "sum", key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sparse_cross_entropy. This method simply wraps the function, and so the docstring for ivy.sparse_cross_entropy also applies to this method with minimal changes. Parameters ---------- self input container containing the true labels as logits. pred input array or container containing the predicted labels as logits. axis the axis along which to compute the cross-entropy. If axis is ``-1``, the cross-entropy will be computed along the last dimension. Default: ``-1``. epsilon a float in [0.0, 1.0] specifying the amount of smoothing when calculating the loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The sparse cross-entropy loss between the given distributions. Examples -------- >>> x = ivy.Container(a=ivy.array([1, 0, 0]),b=ivy.array([0, 0, 1])) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> z = x.sparse_cross_entropy(y) >>> print(z) { a: ivy.array([1.61, 0.511, 0.511]), b: ivy.array([0.223, 0.223, 1.61]) } """ return self.static_sparse_cross_entropy( self, pred, axis=axis, epsilon=epsilon, reduction=reduction, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.manipulation # For Review # global from typing import ( Optional, Union, List, Tuple, Dict, Iterable, Sequence, ) from numbers import Number # local import ivy from ivy.container.base import ContainerBase
[docs]def static_concat( xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container], ...], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], /, *, axis: Optional[int] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.concat. This method simply wraps the function, and so the docstring for ivy.concat also applies to this method with minimal changes. """ return ContainerBase.cont_multi_map_in_function( "concat", xs, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def concat( self: ivy.Container, /, xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container], ...], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], *, axis: Optional[int] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.concat. This method simply wraps the function, and so the docstring for ivy.concat also applies to this method with minimal changes. """ new_xs = xs.cont_copy() if ivy.is_ivy_container(xs) else xs.copy() new_xs.insert(0, self.cont_copy()) return self.static_concat( new_xs, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_expand_dims( x: ivy.Container, /, *, axis: Union[int, Sequence[int]] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.expand_dims. This method simply wraps the function, and so the docstring for ivy.expand_dims also applies to this method with minimal changes. Parameters ---------- x input container. axis position where a new axis (dimension) of size one will be added. If an element of the container has the rank of ``N``, then the ``axis`` needs to be between ``[-N-1, N]``. Default: ``0``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the elements of ``x``, but with the dimensions of its elements added by one in a given ``axis``. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1.]), ... b=ivy.array([3., 4.]), ... c=ivy.array([6., 7.])) >>> y = ivy.Container.static_expand_dims(x, axis=1) >>> print(y) { a: ivy.array([[0.], [1.]]), b: ivy.array([[3.], [4.]]), c: ivy.array([[6.], [7.]]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.]), ... c=ivy.array([6., 7., 8.])) >>> container_axis = ivy.Container(a=0, b=-1, c=(0,1)) >>> y = ivy.Container.static_expand_dims(x, axis=container_axis) >>> print(y) { a: ivy.array([[0., 1., 2.]]), b: ivy.array([[3.], [4.], [5.]]), c: ivy.array([[[6., 7., 8.]]]) } """ return ContainerBase.cont_multi_map_in_function( "expand_dims", x, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def expand_dims( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.expand_dims. This method simply wraps the function, and so the docstring for ivy.expand_dims also applies to this method with minimal changes. Parameters ---------- self input container. axis position where a new axis (dimension) of size one will be added. If an element of the container has the rank of ``N``, the ``axis`` needs to be between ``[-N-1, N]``. Default: ``0``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the elements of ``self``, but with the dimensions of its elements added by one in a given ``axis``. Examples -------- >>> x = ivy.Container(a=ivy.array([[0., 1.], ... [2., 3.]]), ... b=ivy.array([[4., 5.], ... [6., 7.]])) >>> y = x.expand_dims(axis=1) >>> print(y) { a: ivy.array([[[0., 1.]], [[2., 3.]]]), b: ivy.array([[[4., 5.]], [[6., 7.]]]) } """ return self.static_expand_dims( self, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_split( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, num_or_size_splits: Optional[Union[int, Sequence[int]]] = None, axis: Optional[int] = 0, with_remainder: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> Union[ivy.Container, List[ivy.Container]]: """ ivy.Container static method variant of ivy.split. This method simply wraps the function, and so the docstring for ivy.split also applies to this method with minimal changes. Parameters ---------- x array to be divided into sub-arrays. num_or_size_splits Number of equal arrays to divide the array into along the given axis if an integer. The size of each split element if a sequence of integers. Default is to divide into as many 1-dimensional arrays as the axis dimension. axis The axis along which to split, default is ``0``. with_remainder If the tensor does not split evenly, then store the last remainder entry. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- A container with list of sub-arrays. Examples -------- >>> x = ivy.Container(a=ivy.array([2, 1, 5, 9]), b=ivy.array([3, 7, 2, 11])) >>> y = ivy.Container.static_split(x, num_or_size_splits=2) >>> print(y) [{ a: ivy.array([2, 1]), b: ivy.array([3, 7]) }, { a: ivy.array([5, 9]), b: ivy.array([2, 11]) }] """ return ContainerBase.cont_multi_map_in_function( "split", x, num_or_size_splits=num_or_size_splits, axis=axis, with_remainder=with_remainder, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def split( self: ivy.Container, /, *, num_or_size_splits: Optional[Union[int, Sequence[int]]] = None, axis: Optional[int] = 0, with_remainder: Optional[bool] = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> Union[ivy.Container, List[ivy.Container]]: """ ivy.Container instance method variant of ivy.split. This method simply wraps the function, and so the docstring for ivy.split also applies to this method with minimal changes. Parameters ---------- self array to be divided into sub-arrays. num_or_size_splits Number of equal arrays to divide the array into along the given axis if an integer. The size of each split element if a sequence of integers. Default is to divide into as many 1-dimensional arrays as the axis dimension. axis The axis along which to split, default is ``0``. with_remainder If the tensor does not split evenly, then store the last remainder entry. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- A container with list of sub-arrays. Examples -------- >>> x = ivy.Container(a=ivy.array([2, 1, 5, 9]), b=ivy.array([3, 7, 2, 11])) >>> y = x.split(num_or_size_splits=2) >>> print(y) [{ a: ivy.array([2, 1]), b: ivy.array([3, 7]) }, { a: ivy.array([5, 9]), b: ivy.array([2, 11]) }] """ return self.static_split( self, num_or_size_splits=num_or_size_splits, axis=axis, with_remainder=with_remainder, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_permute_dims( x: ivy.Container, /, axes: Tuple[int, ...], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.permute_dims. This method simply wraps the function, and so the docstring for ivy.permute_dims also applies to this method with minimal changes. Parameters ---------- self input container. axis tuple containing a permutation of (0, 1, ..., N-1) where N is the number of axes (dimensions) of x. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the elements of ``self`` permuted along the given axes. Examples -------- >>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), b=ivy.array([[3., 4., 5.]])) >>> y = ivy.Container.static_permute_dims(x, axes=(1, 0)) >>> print(y) { a:ivy.array([[0.],[1.],[2.]]), b:ivy.array([[3.],[4.],[5.]]) } """ return ContainerBase.cont_multi_map_in_function( "permute_dims", x, axes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def permute_dims( self: ivy.Container, /, axes: Tuple[int, ...], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.permute_dims. This method simply wraps the function, and so the docstring for ivy.permute_dims also applies to this method with minimal changes. Parameters ---------- self input container. axis tuple containing a permutation of (0, 1, ..., N-1) where N is the number of axes (dimensions) of x. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the elements of ``self`` permuted along the given axes. Examples -------- >>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), b=ivy.array([[3., 4., 5.]])) >>> y = x.permute_dims(axes=(1, 0)) >>> print(y) { a:ivy.array([[0.],[1.],[2.]]), b:ivy.array([[3.],[4.],[5.]]) } """ return self.static_permute_dims( self, axes, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_flip( x: ivy.Container, /, *, axis: Optional[Union[int, Sequence[int]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.flip. This method simply wraps the function, and so the docstring for ivy.flip also applies to this method with minimal changes. Parameters ---------- x input container. axis axis (or axes) along which to flip. If axis is None, all input array axes are flipped. If axis is negative, axis is counted from the last dimension. If provided more than one axis, only the specified axes. Default: None. key_chains The key-chains to apply or not apply the method to. Default is None. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container having the same data type and shape as ``x`` and whose elements, relative to ``x``, are reordered. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container.static_flip(x) >>> print(y) { a: ivy.array([1, 0, -1]), b: ivy.array([4, 3, 2]) } >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), ... b=ivy.array([2, 3, 4])) >>> y = ivy.Container.static_flip(x, axis=0) >>> print(y) { a: ivy.array([1, 0, -1]), b: ivy.array([4, 3, 2]) } """ return ContainerBase.cont_multi_map_in_function( "flip", x, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def flip( self: ivy.Container, /, *, axis: Optional[Union[int, Sequence[int]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.flip. This method simply wraps the function, and so the docstring for ivy.flip also applies to this method with minimal changes. Parameters ---------- self input container. axis axis (or axes) along which to flip. If axis is None, all input array axes are flipped. If axis is negative, axis is counted from the last dimension. If provided more than one axis, only the specified axes. Default: None. key_chains The key-chains to apply or not apply the method to. Default is None. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is False. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container having the same data type and shape as ``self`` and whose elements, relative to ``self``, are reordered. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), ... b=ivy.array([2, 3, 4])) >>> y = x.flip() >>> print(y) { a: ivy.array([1, 0, -1]), b: ivy.array([4, 3, 2]) } >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), ... b=ivy.array([2, 3, 4])) >>> y = x.flip(axis=0) >>> print(y) { a: ivy.array([1, 0, -1]), b: ivy.array([4, 3, 2]) } """ return self.static_flip( self, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_reshape( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, shape: Union[ivy.Shape, ivy.NativeShape, Sequence[int]], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, copy: Optional[bool] = None, out: Optional[ivy.Container] = None, order: Optional[str] = "C", allowzero: Optional[bool] = True, ) -> ivy.Container: """ ivy.Container static method variant of ivy.reshape. This method simply wraps the function, and so the docstring for ivy.reshape also applies to this method with minimal changes. Parameters ---------- x input container. shape The new shape should be compatible with the original shape. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions. copy boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. order Read the elements of x using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of indexing. Default order is 'C' Returns ------- ret optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]), ... b=ivy.array([0, 1, 2, 3, 4, 5])) >>> y = ivy.Container.static_reshape(x, (3,2)) >>> print(y) { a: ivy.array([[0, 1], [2, 3], [4, 5]]), b: ivy.array([[0, 1], [2, 3], [4, 5]]) } >>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]), ... b=ivy.array([0, 1, 2, 3, 4, 5])) >>> y = ivy.Container.static_reshape(x, (3,2), order='F') >>> print(y) { a: ivy.array([[0, 3], [1, 4], [2, 5]]), b: ivy.array([[0, 3], [1, 4], [2, 5]]) } """ return ContainerBase.cont_multi_map_in_function( "reshape", x, shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, copy=copy, allowzero=allowzero, out=out, order=order, )
[docs]def reshape( self: ivy.Container, /, shape: Union[ivy.Shape, ivy.NativeShape, Sequence[int]], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, copy: Optional[bool] = None, order: Optional[str] = "C", allowzero: Optional[bool] = True, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.reshape. This method simply wraps the function, and so the docstring for ivy.reshape also applies to this method with minimal changes. Parameters ---------- self input container. shape The new shape should be compatible with the original shape. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions. copy boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. order Read the elements of the input container using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of indexing. Default order is 'C' out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container having the same data type as ``self`` and elements as ``self``. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]), ... b=ivy.array([0, 1, 2, 3, 4, 5])) >>> y = x.reshape((2,3)) >>> print(y) { a: ivy.array([[0, 1, 2], [3, 4, 5]]), b: ivy.array([[0, 1, 2], [3, 4, 5]]) } >>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]), ... b=ivy.array([0, 1, 2, 3, 4, 5])) >>> y = x.reshape((2,3), order='F') >>> print(y) { a: ivy.array([[0, 2, 4], [1, 3, 5]]), b: ivy.array([[0, 2, 4], [1, 3, 5]]) } """ return self.static_reshape( self, shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, copy=copy, allowzero=allowzero, out=out, order=order, )
[docs]def static_roll( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, shift: Union[int, Tuple[int, ...], ivy.Container], *, axis: Optional[Union[int, Tuple[int, ...], ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.roll. This method simply wraps the function, and so the docstring for ivy.roll also applies to this method with minimal changes. Parameters ---------- x input container. shift number of places by which the elements are shifted. If ``shift`` is a tuple, then ``axis`` must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element in ``shift``. If ``shift`` is an ``int`` and ``axis`` a tuple, then the same ``shift`` must be used for all specified axes. If a shift is positivclipe, then array elements must be shifted positively (toward larger indices) along the dimension of ``axis``. If a shift is negative, then array elements must be shifted negatively (toward smaller indices) along the dimension of ``axis``. axis axis (or axes) along which elements to shift. If ``axis`` is ``None``, the array must be flattened, shifted, and then restored to its original shape. Default ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container having the same data type as ``x`` and whose elements, relative to ``x``, are shifted. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_roll(x, 1) >>> print(y) { a: ivy.array([2., 0., 1.]), b: ivy.array([5., 3., 4.]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> shift = ivy.Container(a=1, b=-1) >>> y = ivy.Container.static_roll(x, shift) >>> print(y) { a: ivy.array([2., 0., 1.]), b: ivy.array([4., 5., 3.]) } """ return ContainerBase.cont_multi_map_in_function( "roll", x, shift, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def roll( self: ivy.Container, /, shift: Union[int, Sequence[int], ivy.Container], *, axis: Optional[Union[int, Sequence[int], ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.roll. This method simply wraps the function, and so the docstring for ivy.roll also applies to this method with minimal changes. Parameters ---------- self input container. shift number of places by which the elements are shifted. If ``shift`` is a tuple, then ``axis`` must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element in ``shift``. If ``shift`` is an ``int`` and ``axis`` a tuple, then the same ``shift`` must be used for all specified axes. If a shift is positive, then array elements must be shifted positively (toward larger indices) along the dimension of ``axis``. If a shift is negative, then array elements must be shifted negatively (toward smaller indices) along the dimension of ``axis``. axis axis (or axes) along which elements to shift. If ``axis`` is ``None``, the array must be flattened, shifted, and then restored to its original shape. Default ``None``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container having the same data type as ``self`` and whose elements, relative to ``self``, are shifted. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.roll(1) >>> print(y) { a: ivy.array([2., 0., 1.]), b: ivy.array([5., 3., 4.]) } """ return self.static_roll( self, shift, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_squeeze( x: ivy.Container, /, axis: Union[int, Sequence[int]], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.squeeze. This method simply wraps the function, and so the docstring for ivy.squeeze also applies to this method with minimal changes. Parameters ---------- x input container. axis axis (or axes) to squeeze. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container with the results. Examples -------- >>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]), ... b=ivy.array([[[11.], [12.]]])) >>> y = ivy.Container.static_squeeze(x, 0) >>> print(y) { a: ivy.array([[10., 11.]]), b: ivy.array([[11., 12.]]) } >>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]), ... b=ivy.array([[[11.], [12.]]])) >>> y = ivy.Container.static_squeeze(x, [0, 2]) >>> print(y) { a: ivy.array([[10.], [11.]]), b: ivy.array([[11.], [12.]]) } """ return ContainerBase.cont_multi_map_in_function( "squeeze", x, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def squeeze( self: ivy.Container, /, axis: Union[int, Sequence[int]], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.squeeze. This method simply wraps the function, and so the docstring for ivy.squeeze also applies to this method with minimal changes. Parameters ---------- self input container. axis axis (or axes) to squeeze. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container with the results. Examples -------- >>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]), ... b=ivy.array([[[11.], [12.]]])) >>> y = x.squeeze(2) >>> print(y) { a: ivy.array([[10., 11.]]), b: ivy.array([[11., 12.]]) } >>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]), ... b=ivy.array([[[11.], [12.]]])) >>> y = x.squeeze(0) >>> print(y) { a: ivy.array([[10.], [11.]]), b: ivy.array([[11.], [12.]]) } """ return self.static_squeeze( self, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_stack( xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], /, *, axis: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.stack. This method simply wraps the function, and so the docstring for ivy.stack also applies to this method with minimal changes. Parameters ---------- xs Container with leaves to join. Each array leavve must have the same shape. axis axis along which the array leaves will be joined. More details can be found in the docstring for ivy.stack. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container with the results. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> z = ivy.Container.static_stack(x,axis = 1) >>> print(z) { a: ivy.array([[0, 2], [1, 3]]), b: ivy.array([[4], [5]]) } >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]])) >>> z = ivy.Container.static_stack([x,y]) >>> print(z) { a: ivy.array([[[0, 1], [2, 3]], [[3, 2], [1, 0]]]), b: ivy.array([[[4, 5]], [[1, 0]]]) } >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]])) >>> z = ivy.Container.static_stack([x,y],axis=1) >>> print(z) { a: ivy.array([[[0, 1], [3, 2]], [[2, 3], [1, 0]]]), b: ivy.array([[[4, 5], [1, 0]]]) } """ return ContainerBase.cont_multi_map_in_function( "stack", xs, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def stack( self: ivy.Container, /, xs: Union[ Tuple[Union[ivy.Array, ivy.NativeArray, ivy.Container]], List[Union[ivy.Array, ivy.NativeArray, ivy.Container]], ], *, axis: int = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.stack. This method simply wraps the function, and so the docstring for ivy.stack also applies to this method with minimal changes. Parameters ---------- self Container with leaves to join with leaves of other arrays/containers. Each array leave must have the same shape. xs Container with other leaves to join. Each array leave must have the same shape. axis axis along which the array leaves will be joined. More details can be found in the docstring for ivy.stack. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret an output container with the results. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]])) >>> x.stack([y]) { a: ivy.array([[[0, 1], [2, 3]], [[3, 2], [1, 0]]]), b: ivy.array([[[4, 5]], [[1, 0]]]) } """ new_xs = xs.cont_copy() if ivy.is_ivy_container(xs) else xs.copy() new_xs.insert(0, self.cont_copy()) return self.static_stack( new_xs, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_repeat( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, repeats: Union[int, Iterable[int]], *, axis: Optional[Union[int, Sequence[int]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.repeat. This method simply wraps the function, and so the docstring for ivy.repeat also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_repeat(2) >>> print(y) { a: ivy.array([0., 0., 1., 1., 2., 2.]), b: ivy.array([3., 3., 4., 4., 5., 5.]) } """ return ContainerBase.cont_multi_map_in_function( "repeat", x, repeats, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def repeat( self: ivy.Container, /, repeats: Union[int, Iterable[int]], *, axis: Optional[Union[int, Sequence[int]]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.repeat. This method simply wraps the function, and so the docstring for ivy.repeat also applies to this method with minimal changes. Parameters ---------- x Input container. repeats The number of repetitions for each element. repeats is broadcast to fit the shape of the given axis. axis The axis along which to repeat values. By default, use the flattened input array, and return a flat output array. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The output container with repreated leaves. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.repeat(2) >>> print(y) { a: ivy.array([0., 0., 1., 1., 2., 2.]), b: ivy.array([3., 3., 4., 4., 5., 5.]) } """ return self.static_repeat( self, repeats, axis=axis, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_tile( x: ivy.Container, /, repeats: Iterable[int], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.tile. This method simply wraps the function, and so the docstring for ivy.tile also applies to this method with minimal changes. Parameters ---------- x Input Container. repeats The number of repetitions of x along each axis. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The container output with tiled leaves. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = ivy.Container.static_tile((2,3)) >>> print(y) { a: ivy.array([[0,1,0,1,0,1], [2,3,2,3,2,3], [0,1,0,1,0,1], [2,3,2,3,2,3]]), b: ivy.array([[4,5,4,5,4,5], [4,5,4,5,4,5]]) } """ return ContainerBase.cont_multi_map_in_function( "tile", x, repeats, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def tile( self: ivy.Container, /, repeats: Iterable[int], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.tile. This method simply wraps the function, and so the docstring for ivy.tile also applies to this method with minimal changes. Parameters ---------- self Input container. repeats The number of repetitions of x along each axis. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The container output with tiled leaves. Examples -------- >>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]])) >>> y = x.tile((2,3)) >>> print(y) { a: (<classivy.array.array.Array>shape=[4,6]), b: (<classivy.array.array.Array>shape=[2,6]) } """ return self.static_tile( self, repeats, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_constant_pad( x: ivy.Container, /, pad_width: Iterable[Tuple[int]], *, value: Number = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.constant_pad. This method simply wraps the function, and so the docstring for ivy.constant_pad also applies to this method with minimal changes. Parameters ---------- x Input container with leaves to pad. pad_width Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x. value The constant value to pad the array with. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Output container with padded array leaves of rank equal to x with shape increased according to pad_width. Examples -------- >>> x = ivy.Container(a = ivy.array([1, 2, 3]), b = ivy.array([4, 5, 6])) >>> y = ivy.Container.static_constant_pad(x, pad_width = [[2, 3]]) >>> print(y) { a: ivy.array([0, 0, 1, 2, 3, 0, 0, 0]), b: ivy.array([0, 0, 4, 5, 6, 0, 0, 0]) } """ return ContainerBase.cont_multi_map_in_function( "constant_pad", x, pad_width, value=value, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def constant_pad( self: ivy.Container, /, pad_width: Iterable[Tuple[int]], *, value: Number = 0, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.constant_pad. This method simply wraps the function, and so the docstring for ivy.constant_pad also applies to this method with minimal changes. Parameters ---------- self Input container with leaves to pad. pad_width Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x. value The constant value to pad the array with. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Output container with padded array leaves of rank equal to x with shape increased according to pad_width. Examples -------- >>> x = ivy.Container(a = ivy.array([1, 2, 3]), b = ivy.array([4, 5, 6])) >>> y = x.constant_pad(pad_width = [[2, 3]]) >>> print(y) { a: ivy.array([0, 0, 1, 2, 3, 0, 0, 0]), b: ivy.array([0, 0, 4, 5, 6, 0, 0, 0]) } """ return self.static_constant_pad( self, pad_width, value=value, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_zero_pad( x: ivy.Container, /, pad_width: Iterable[Tuple[int]], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.zero_pad. This method simply wraps the function, and so the docstring for ivy.zero_pad also applies to this method with minimal changes. Parameters ---------- x Input array to pad. pad_width Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Padded array of rank equal to x with shape increased according to pad_width. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a = ivy.array([1., 2., 3.]), b = ivy.array([3., 4., 5.])) >>> y = ivy.zero_pad(x, pad_width = [[2, 3]]) >>> print(y) { a: ivy.array([0., 0., 1., 2., 3., 0., 0., 0.]), b: ivy.array([0., 0., 3., 4., 5., 0., 0., 0.]) } """ return ContainerBase.cont_multi_map_in_function( "zero_pad", x, pad_width, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def zero_pad( self: ivy.Container, /, pad_width: Iterable[Tuple[int]], *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.zero_pad. This method simply wraps the function, and so the docstring for ivy.zero_pad also applies to this method with minimal changes. Parameters ---------- self Input array to pad. pad_width Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Padded array of rank equal to x with shape increased according to pad_width. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a = ivy.array([1., 2., 3.]), b = ivy.array([3., 4., 5.])) >>> y = x.zero_pad(pad_width = [[2, 3]]) >>> print(y) { a: ivy.array([0., 0., 1., 2., 3., 0., 0., 0.]), b: ivy.array([0., 0., 3., 4., 5., 0., 0., 0.]) } """ return self.static_zero_pad( self, pad_width, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_swapaxes( x: ivy.Container, axis0: int, axis1: int, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.swapaxes. This method simply wraps the function, and so the docstring for ivy.swapaxes also applies to this method with minimal changes. Parameters ---------- x Input container axis0 First axis to be swapped. axis1 Second axis to be swapped. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret x with its axes permuted. >>> a = ivy.array([[1, 2, 3], [4, 5, 6]]) >>> b = ivy.array([[7, 8, 9], [10, 11, 12]]) >>> x = ivy.Container(a = a, b = b) >>> y = x.swapaxes(0, 1) >>> print(y) { a: ivy.array([[1, 4], [2, 5], [3, 6]]), b: ivy.array([[7, 10], [8, 11], [9, 12]]) } """ return ContainerBase.cont_multi_map_in_function( "swapaxes", x, axis0, axis1, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def swapaxes( self: ivy.Container, axis0: int, axis1: int, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.swapaxes. This method simply wraps the function, and so the docstring for ivy.swapaxes also applies to this method with minimal changes. Parameters ---------- self Input container. axis0 First axis to be swapped. axis1 Second axis to be swapped. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret x with its axes permuted. Examples -------- >>> a = ivy.array([[1, 2, 3], [4, 5, 6]]) >>> b = ivy.array([[7, 8, 9], [10, 11, 12]]) >>> x = ivy.Container(a = a, b = b) >>> y = x.swapaxes(0, 1) >>> print(y) { a: ivy.array([[1, 4], [2, 5], [3, 6]]), b: ivy.array([[7, 10], [8, 11], [9, 12]]) } """ return self.static_swapaxes( self, axis0, axis1, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_unstack( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: int = 0, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.unstack. This method simply wraps the function, and so the docstring for ivy.unstack also applies to this method with minimal changes. Parameters ---------- x Input array or container to unstack. axis Axis for which to unpack the array. keepdims Whether to keep dimension 1 in the unstack dimensions. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret List of arrays, unpacked along specified dimensions, or containers with arrays unpacked at leaves Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])) >>> y = ivy.Container.static_unstack(x, axis=0) >>> print(y) [{ a: ivy.array([[1, 2], [3, 4]]), b: ivy.array([[9, 10], [11, 12]]) }, { a: ivy.array([[5, 6], [7, 8]]), b: ivy.array([[13, 14], [15, 16]]) }] >>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])) >>> y = ivy.Container.static_unstack(x, axis=1, keepdims=True) >>> print(y) [{ a: ivy.array([[[1, 2]], [[5, 6]]]), b: ivy.array([[[9, 10]], [[13, 14]]]) }, { a: ivy.array([[[3, 4]], [[7, 8]]]), b: ivy.array([[[11, 12]], [[15, 16]]]) }] """ return ContainerBase.cont_multi_map_in_function( "unstack", x, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def unstack( self: ivy.Container, /, *, axis: int = 0, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.unstack. This method simply wraps the function, and so the docstring for ivy.unstack also applies to this method with minimal changes. Parameters ---------- self Input container to unstack at leaves. axis Axis for which to unpack the array. keepdims Whether to keep dimension 1 in the unstack dimensions. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Containers with arrays unpacked at leaves Examples -------- With one :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])) >>> x.unstack(axis=0) [{ a: ivy.array([[1, 2], [3, 4]]), b: ivy.array([[9, 10], [11, 12]]) }, { a: ivy.array([[5, 6], [7, 8]]), b: ivy.array([[13, 14], [15, 16]]) }] """ return self.static_unstack( self, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_clip( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], x_min: Optional[Union[Number, ivy.Array, ivy.NativeArray]] = None, x_max: Optional[Union[Number, ivy.Array, ivy.NativeArray]] = None, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.clip. This method simply wraps the function, and so the docstring for ivy.clip also applies to this method with minimal changes. Parameters ---------- x Input array or container containing elements to clip. x_min Minimum value. x_max Maximum value. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the elements of x, but where values < x_min are replaced with x_min, and those > x_max with x_max. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_clip(x, 1., 5.) >>> print(y) { a: ivy.array([1., 1., 2.]), b: ivy.array([3., 4., 5.]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3., 4., 5.])) >>> x_min = ivy.Container(a=0, b=0) >>> x_max = ivy.Container(a=1, b=1) >>> y = ivy.Container.static_clip(x, x_min, x_max) >>> print(y) { a: ivy.array([0., 1., 1.]), b: ivy.array([1., 1., 1.]) } """ return ContainerBase.cont_multi_map_in_function( "clip", x, x_min, x_max, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def clip( self: ivy.Container, x_min: Optional[Union[Number, ivy.Array, ivy.NativeArray]] = None, x_max: Optional[Union[Number, ivy.Array, ivy.NativeArray]] = None, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.clip. This method simply wraps the function, and so the docstring for ivy.clip also applies to this method with minimal changes. Parameters ---------- self Input container containing elements to clip. x_min Minimum value. x_max Maximum value. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container with the elements of x, but where values < x_min are replaced with x_min, and those > x_max with x_max. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.clip(1,2) >>> print(y) { a: ivy.array([1., 1., 2.]), b: ivy.array([2., 2., 2.]) } """ return self.static_clip( self, x_min, x_max, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.norms # global from typing import Optional, List, Union # local import ivy from ivy.container.base import ContainerBase # ToDo: implement all methods here as public instance methods # noinspection PyMissingConstructor
[docs]def layer_norm( self: ivy.Container, normalized_idxs: List[int], /, *, scale: Optional[Union[ivy.Array, float]] = None, b: Optional[Union[ivy.Array, float]] = None, epsilon: float = ivy._MIN_BASE, new_std: float = 1.0, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.layer_norm. This method simply wraps the function, and so the docstring for ivy.layer_norm also applies to this method with minimal changes. Parameters ---------- self Input container normalized_idxs Indices to apply the normalization to. scale Learnable gamma variables for elementwise post-multiplication, default is ``None``. b Learnable beta variables for elementwise post-addition, default is ``None``. epsilon small constant to add to the denominator, use global ivy._MIN_BASE by default. new_std The standard deviation of the new normalized values. Default is 1. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret The layer after applying layer normalization. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container({'a': ivy.array([7., 10., 12.]), ... 'b': ivy.array([[1., 2., 3.], [4., 5., 6.]])}) >>> normalized_idxs = [0] >>> norm = x.layer_norm(normalized_idxs, epsilon=1.25, scale=0.3) >>> print(norm) { a: ivy.array([-0.342, 0.0427, 0.299]), b: ivy.array([[-0.241, -0.241, -0.241, [0.241, 0.241, 0.241]]) } With multiple :class:`ivy.Container` inputs: >>> x = ivy.Container({'a': ivy.array([7., 10., 12.]), ... 'b': ivy.array([[1., 2., 3.], [4., 5., 6.]])}) >>> normalized_idxs = ivy.Container({'a': [0], 'b': [1]}) >>> new_std = ivy.Container({'a': 1.25, 'b': 1.5}) >>> bias = ivy.Container({'a': [0.2, 0.5, 0.7], 'b': 0.3}) >>> norm = x.layer_norm(normalized_idxs, new_std=new_std, b=b) >>> print(norm) { a: ivy.array([-1.62, 0.203, 1.42]), b: ivy.array([[-1.84, 0., 1.84], [-1.84, 0., 1.84]]) } """ return ivy.layer_norm( self, normalized_idxs, scale=scale, b=b, epsilon=epsilon, new_std=new_std, out=out, )
#ivy.container.random # global from typing import Optional, Union, List, Dict # local import ivy from ivy.container.base import ContainerBase # noinspection PyMissingConstructor
[docs]def static_random_uniform( *, low: Union[float, ivy.Container, ivy.Array, ivy.NativeArray] = 0.0, high: Union[float, ivy.Container, ivy.Array, ivy.NativeArray] = 1.0, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.random_uniform. This method simply wraps the function, and so the docstring for ivy.random_uniform also applies to this method with minimal changes. Parameters ---------- low Lower boundary of the output interval. All values generated will be greater than or equal to ``low``. If array, must have same shape as ``high``. high Upper boundary of the output interval. All the values generated will be less than ``high``. If array, must have same shape as ``low``. shape If the given shape is, e.g ``(m, n, k)``, then ``m * n * k`` samples are drawn. Can only be specified when ``low`` and ``high`` are numeric values, else exception will be raised. Default is ``None``, where a single value is returned. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output array data type. If ``dtype`` is ``None``, the output array data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Drawn samples from the parameterized uniform distribution. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> ivy.Container.static_random_uniform(low=x, high=y, device='cpu', ... dtype='float64') { a: ivy.array([[10.8, 23.7], [17., 16.6]]), b: ivy.array([[2.35, 3.69], [17.4, 48.]]) } With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs: >>> x = ivy.array([-1.0,-9.0,-3.4]) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> ivy.Container.static_random_uniform(low=x, high=y) { a: ivy.array([0.481, -8.03, -2.74]), b: ivy.array([0.0999, -7.38, -1.29]) } """ return ContainerBase.cont_multi_map_in_function( "random_uniform", low=low, high=high, shape=shape, device=device, dtype=dtype, seed=seed, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def random_uniform( self: ivy.Container, /, *, high: Union[float, ivy.Container, ivy.Array, ivy.NativeArray] = 1.0, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.random_uniform. This method simply wraps the function, and so the docstring for ivy.random_uniform also applies to this method with minimal changes. Parameters ---------- self Lower boundary of the output interval. All values generated will be greater than or equal to ``low``. If array, must have same shape as ``high``. high Upper boundary of the output interval. All the values generated will be less than ``high``. If array, must have same shape as ``low``. shape If the given shape is, e.g ``(m, n, k)``, then ``m * n * k`` samples are drawn. Can only be specified when ``low`` and ``high`` are numeric values, else exception will be raised. Default is ``None``, where a single value is returned. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output array data type. If ``dtype`` is ``None``, the output array data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Drawn samples from the parameterized uniform distribution. Examples -------- >>> x = ivy.Container(a=ivy.array([7.5,6.7,0.9]), b=ivy.array([8.7,9.8,4.5])) >>> x.random_uniform(high=17.4) { a: ivy.array([11.2, 10.5, 13.1]), b: ivy.array([11.2, 11.9, 6.01]) } >>> x.random_uniform(high=10.2, device='cpu') { a: ivy.array([8.55, 10.1, 4.08]), b: ivy.array([9.45, 9.9, 8.6]) } >>> x.random_uniform(high=14.2, dtype='float16') { a: ivy.array([12.4, 11.7, 7.25]), b: ivy.array([11.8, 11.8, 4.96]) } >>> x.random_uniform(high=10.8, device='cpu', dtype='float64') { a: ivy.array([8.86, 9.24, 6.43]), b: ivy.array([8.95, 10.1, 8.51]) } >>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_uniform(high=11.2, device='cpu', dtype='float64', out=z) { a: ivy.array([9.6, 8.24, 3.67]), b: ivy.array([9.29, 11.2, 9.84]) } >>> y = ivy.Container(a=10.4, b=17.4) >>> x.random_uniform(high=y) { a: ivy.array([8.24, 9.22, 1.52]), b: ivy.array([16.5, 13.4, 17.3]) } >>> x.random_uniform(high=y, device='cpu') { a: ivy.array([8.55, 10.1, 4.08]), b: ivy.array([9.45, 9.9, 8.6]) } >>> x.random_uniform(high=y, dtype='float16') { a: ivy.array([12.4, 11.7, 7.25]), b: ivy.array([11.8, 11.8, 4.96]) } >>> x.random_uniform(high=y, device='cpu', dtype='float64') { a: ivy.array([8.86, 9.24, 6.43]), b: ivy.array([8.95, 10.1, 8.51]) } >>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_uniform(high=y, device='cpu', dtype='float64', out=z) { a: ivy.array([9.6, 8.24, 3.67]), b: ivy.array([9.29, 11.2, 9.84]) } >>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> x.random_uniform(high=y) { a: ivy.array([[10.4, 17.], [9.81, 10.9]]), b: ivy.array([[3.6, 4.31], [18.8, 54.2]]) } >>> x.random_uniform(high=y, device='cpu') { a: ivy.array([[10.1, 7.93], [7.98, 6.]]), b: ivy.array([[4.28, 4.65], [13.9, 28.9]]) } >>> x.random_uniform(high=y, dtype='float16') { a: ivy.array([[10.6, 28.], [16.4, 4.92]]), b: ivy.array([[3.61, 4.82], [12.6, 10.2]]) } >>> x.random_uniform(high=y, device='cpu', dtype='float64') { a: ivy.array([[10.7, 28.4], [9.29, 17.4]]), b: ivy.array([[1.88, 4.94], [17., 9.68]]) } >>> z = ivy.Container(a=ivy.zeros((2,2)), b=ivy.ones((2,2))) >>> x.random_uniform(high=y, device='cpu', dtype='float64', out=z) { a: ivy.array([[10.4, 29.8], [12.1, 3.9]]), b: ivy.array([[3.79, 5.4], [16.2, 31.7]]) } """ return self.static_random_uniform( low=self, high=high, shape=shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, device=device, dtype=dtype, seed=seed, out=out, )
[docs]def static_random_normal( *, mean: Union[float, ivy.Container, ivy.Array, ivy.NativeArray] = 0.0, std: Union[float, ivy.Container, ivy.Array, ivy.NativeArray] = 1.0, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.random_normal. This method simply wraps the function, and so the docstring for ivy.random_normal also applies to this method with minimal changes. Parameters ---------- mean The mean of the normal distribution to sample from. Default is ``0.0``. std The standard deviation of the normal distribution to sample from. Must be non-negative. Default is ``1.0``. shape If the given shape is, e.g ``(m, n, k)``, then ``m * n * k`` samples are drawn. Can only be specified when ``mean`` and ``std`` are numeric values, else exception will be raised. Default is ``None``, where a single value is returned. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output array data type. If ``dtype`` is ``None``, the output array data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Drawn samples from the parameterized normal distribution. Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> ivy.Container.static_random_normal(mean=x, std=y, device='cpu', ... dtype='float64') { a: ivy.array([[-4.11, 0.651], [19.3, -30.4]]), b: ivy.array([[1.15, 3.39], [-9.35, -13.9]]) } With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs: >>> x = ivy.array([-1.0,-9.0,-3.4]) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> ivy.Container.static_random_normal(mean=x, std=y) { a: ivy.array([-0.651, -9.25, -3.54]), b: ivy.array([0.464, -8.51, -3.75]) } """ return ContainerBase.cont_multi_map_in_function( "random_normal", mean=mean, std=std, shape=shape, device=device, dtype=dtype, seed=seed, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def random_normal( self: ivy.Container, /, *, std: Union[float, ivy.Container, ivy.Array, ivy.NativeArray] = 1.0, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.random_normal. This method simply wraps the function, and so the docstring for ivy.random_normal also applies to this method with minimal changes. Parameters ---------- self The mean of the normal distribution to sample from. Default is ``0.0``. std The standard deviation of the normal distribution to sample from. Must be non-negative. Default is ``1.0``. shape If the given shape is, e.g ``(m, n, k)``, then ``m * n * k`` samples are drawn. Can only be specified when ``mean`` and ``std`` are numeric values, else exception will be raised. Default is ``None``, where a single value is returned. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output array data type. If ``dtype`` is ``None``, the output array data type will be the default floating-point data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Drawn samples from the parameterized normal distribution. Examples -------- >>> x = ivy.Container(a=ivy.array([7.5,6.7,0.9]), ... b=ivy.array([8.7,9.8,4.5])) >>> x.random_normal(std=17.4) { a: ivy.array([11.9, -22.9, -24.8]), b: ivy.array([44.3, -21.6, 2.03]) } >>> x.random_normal(std=10.2, device='cpu') { a: ivy.array([7.82, 6.21, -0.431]), b: ivy.array([13.8, 9.9, 7.64]) } >>> x.random_normal(std=14.2, dtype='float16') { a: ivy.array([-18.3, -3.42, 9.55]), b: ivy.array([-1.31, 7.68, -6.93]) } >>> x.random_normal(std=10.8, device='cpu', dtype='float64') { a: ivy.array([13.4, -3.14, 10.7]), b: ivy.array([11.7, 4.85, 5.83]) } >>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_normal(std=11.2, device='cpu', dtype='float64', out=z) { a: ivy.array([-6.84, 0.274, 14.2]), b: ivy.array([29.1, 7.19, 3.]) } >>> y = ivy.Container(a=10.4, b=17.4) >>> x.random_normal(std=y) { a: ivy.array([-9.5, 8.54, -9.13]), b: ivy.array([-24.5, 18.9, 11.]) } >>> x.random_normal(std=y, device='cpu') { a: ivy.array([8.47, 8.23, 8.69]), b: ivy.array([10.7, 16.2, 16.1]) } >>> x.random_normal(std=y, dtype='float16') { a: ivy.array([8.22, -15.9, 10.4]), b: ivy.array([19.9, 11.5, -2.15]) } >>> x.random_normal(std=y, device='cpu', dtype='float64') { a: ivy.array([19.6, -4.08, 6.09]), b: ivy.array([-23.9, 6.86, 17.6]) } >>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_normal(std=y, device='cpu', dtype='float64', out=z) { a: ivy.array([14.7, 8.99, 8.46]), b: ivy.array([22.9, -5.97, -1.28]) } >>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> x.random_normal(std=y) { a: ivy.array([[10.6, 7.89], [9.39, 19.4]]), b: ivy.array([[3.76, 4.68], [17.7, 24.]]) } >>> x.random_normal(std=y, device='cpu') { a: ivy.array([[30.9, 24.6], [29.9, -25.3]]), b: ivy.array([[8.02, 1.92], [-5.34, -54.1]]) } >>> x.random_normal(std=y, dtype='float16') { a: ivy.array([[7.82, -35.], [11.7, 0.696]]), b: ivy.array([[-4.07, -2.91], [19.2, 46.8]]) } >>> x.random_normal(std=y, device='cpu', dtype='float64') { a: ivy.array([[25.4, 28.3], [19.6, -9.83]]), b: ivy.array([[2.95, 2.48], [-30.8, -40.1]]) } >>> z = ivy.Container(a=ivy.zeros((2,2)), b=ivy.ones((2,2))) >>> x.random_normal(std=y, device='cpu', dtype='float64', out=z) { a: ivy.array([[2.8, -45.6], [-10.4, 0.65]]), b: ivy.array([[3.8, 1.43], [23., 29.4]]) } """ return self.static_random_normal( mean=self, std=std, shape=shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, device=device, dtype=dtype, seed=seed, out=out, )
[docs]def static_multinomial( population_size: int, num_samples: int, /, *, batch_size: int = 1, probs: Union[ivy.Array, ivy.NativeArray, ivy.Container] = None, replace: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.multinomial. This method simply wraps the function, and so the docstring for ivy.multinomial also applies to this method with minimal changes. Parameters ---------- population_size The size of the population from which to draw samples. num_samples Number of independent samples to draw from the population. batch_size Number of tensors to generate. Default is 1. probs The unnormalized probabilities for all elements in population, default is uniform *[batch_shape, population_size]* replace Whether to replace samples once they've been drawn. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Drawn samples from the parameterized normal distribution. """ return ContainerBase.cont_multi_map_in_function( "multinomial", population_size, num_samples, batch_size=batch_size, probs=probs, replace=replace, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, device=device, seed=seed, out=out, )
[docs]def multinomial( self: ivy.Container, population_size: int, num_samples: int, /, *, batch_size: int = 1, replace: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.multinomial. This method simply wraps the function, and so the docstring for ivy.multinomial also applies to this method with minimal changes. Parameters ---------- self The unnormalized probabilities for all elements in population, default is uniform *[batch_shape, population_size]* population_size The size of the population from which to draw samples. num_samples Number of independent samples to draw from the population. batch_size Number of tensors to generate. Default is 1. replace Whether to replace samples once they've been drawn. Default is ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Drawn samples from the parameterized normal distribution. """ return self.static_multinomial( population_size, num_samples, batch_size=batch_size, probs=self, replace=replace, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, device=device, seed=seed, out=out, )
[docs]def static_randint( low: Union[int, ivy.Container, ivy.Array, ivy.NativeArray], high: Union[int, ivy.Container, ivy.Array, ivy.NativeArray], /, *, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.randint. This method simply wraps the function, and so the docstring for ivy.randint also applies to this method with minimal changes. Parameters ---------- low Lowest integer that can be drawn from the distribution. high One above the highest integer that can be drawn from the distribution. shape If the given shape is, e.g ``(m, n, k)``, then ``m * n * k`` samples are drawn. Can only be specified when ``low`` and ``high`` are numeric values, else exception will be raised. Default is ``None``, where a single value is returned. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output array data type. If ``dtype`` is ``None``, the output array data type will be the default integer data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Returns an array with the given shape filled with integers from the uniform distribution in the “half-open” interval [low, high) Examples -------- With :class:`ivy.Container` inputs: >>> x = ivy.Container(a=ivy.array([[9,7],[6,2]]), ... b=ivy.array([[0,2],[10,6]])) >>> y = ivy.Container(a=ivy.array([[10,32],[18,19]]), ... b=ivy.array([[44,5],[23,54]])) >>> ivy.Container.static_randint(x, y, device='cpu', dtype='int32') { a: ivy.array([[9, 27], [16, 17]]), b: ivy.array([[13, 3], [16, 19]]) } With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs: >>> x = ivy.array([-1,-9,3]) >>> y = ivy.Container(a=ivy.array([4,7,9]),b=ivy.array([14,17,34])) >>> ivy.Container.static_randint(x, y) { a: ivy.array([1, 6, 5]), b: ivy.array([0, 10, 17]) } """ return ContainerBase.cont_multi_map_in_function( "randint", low, high, shape=shape, device=device, dtype=dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, seed=seed, out=out, )
[docs]def randint( self: ivy.Container, high: Union[int, ivy.Container, ivy.Array, ivy.NativeArray], /, *, shape: Optional[Union[ivy.Shape, ivy.NativeShape, ivy.Container]] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, device: Optional[Union[ivy.Device, ivy.NativeDevice, ivy.Container]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, seed: Optional[int] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.randint. This method simply wraps the function, and so the docstring for ivy.randint also applies to this method with minimal changes. Parameters ---------- self Lowest integer that can be drawn from the distribution. high One above the highest integer that can be drawn from the distribution. shape If the given shape is, e.g ``(m, n, k)``, then ``m * n * k`` samples are drawn. Can only be specified when ``low`` and ``high`` are numeric values, else exception will be raised. Default is ``None``, where a single value is returned. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None). dtype output array data type. If ``dtype`` is ``None``, the output array data type will be the default integer data type. Default ``None`` seed A python integer. Used to create a random seed distribution out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret Returns an array with the given shape filled with integers from the uniform distribution in the “half-open” interval [low, high) Examples -------- >>> x = ivy.Container(a=ivy.array([7,6,0]), ... b=ivy.array([8,9,4])) >>> x.randint(30) { a: ivy.array([23, 15, 20]), b: ivy.array([28, 22, 18]) } >>> x.randint(10, device='cpu') { a: ivy.array([9, 7, 7]), b: ivy.array([8, 9, 9]) } >>> x.randint(102, dtype='int8') { a: ivy.array([9, 8, 2]), b: ivy.array([62, 62, 60]) } >>> x.randint(54, device='cpu', dtype='int64') { a: ivy.array([30, 29, 26]), b: ivy.array([24, 24, 21]) } >>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.randint(21, device='cpu', dtype='int8', out=z) { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) } >>> y = ivy.Container(a=54, b=17) >>> x.randint(y) { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) } >>> x.randint(y, device='cpu') { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) } >>> x.randint(y, dtype='int64') { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) } >>> x.randint(y, device='cpu', dtype='int32') { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) } >>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.randint(y, device='cpu', dtype='int16', out=z) { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) } >>> x = ivy.Container(a=ivy.array([[9,7],[6,2]]), ... b=ivy.array([[0,2],[10,6]])) >>> y = ivy.Container(a=ivy.array([[10,32],[18,19]]), ... b=ivy.array([[44,5],[23,54]])) >>> x.randint(y) { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) } >>> x.randint(y, device='cpu') { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) } >>> x.randint(y, dtype='int64') { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) } >>> x.randint(y, device='cpu', dtype='int32') { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) } >>> z = ivy.Container(a=ivy.zeros((2,2)), b=ivy.ones((2,2))) >>> x.randint(y, device='cpu', dtype='int16', out=z) { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) } """ return self.static_randint( self, high, shape=shape, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, device=device, dtype=dtype, seed=seed, out=out, )
[docs]def static_shuffle( x: Union[int, ivy.Container, ivy.Array, ivy.NativeArray], /, *, seed: Optional[int] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container static method variant of ivy.shuffle. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes. Parameters ---------- x Input array or container. Should have a numeric data type. seed A python integer. Used to create a random seed distribution key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container object, shuffled along the first dimension. Examples -------- >>> x = ivy.Container(a=ivy.array([7, 6, 0]), ... b=ivy.array([8, 9, 4])) >>> ivy.Container.static_shuffle(x) { a: ivy.array([7, 0, 6]), b: ivy.array([8, 4, 9]) } """ return ContainerBase.cont_multi_map_in_function( "shuffle", x, seed=seed, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def shuffle( self: ivy.Container, /, *, seed: Optional[int] = None, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.shuffle. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes. Parameters ---------- self Input container. Should have a numeric data type. seed A python integer. Used to create a random seed distribution key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret A container object, shuffled along the first dimension. Examples -------- >>> x = ivy.Container(a=ivy.array([5, 2, 9]), ... b=ivy.array([7, 1, 6])) >>> ivy.Container.shuffle(x) { a: ivy.array([9, 5, 2]), b: ivy.array([6, 7, 1]) } """ return self.static_shuffle( self, seed=seed, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.searching # global from numbers import Number from typing import Optional, Union, List, Dict # local import ivy from ivy.container.base import ContainerBase # noinspection PyMissingConstructor
[docs]def static_argmax( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Optional[int] = None, keepdims: bool = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, select_last_index: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.argmax. This method simply wraps the function, and so the docstring for ivy.argmax also applies to this method with minimal changes. Parameters ---------- x input array or container. Should have a numeric data type. axis axis along which to search. If None, the function must return the index of the maximum value of the flattened array. Deafult: ``None``. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array. dtype Optional data type of the output array. out If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. Returns ------- ret a container containing the indices of the maximum values across the specified axis. Examples -------- >>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]),\ ... b=ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> y = ivy.Container.static_argmax(x, axis=1, keepdims=True) >>> print(y) { a: ivy.array([[0], [2]]), b: ivy.array([[2], [0]]) } """ return ContainerBase.cont_multi_map_in_function( "argmax", x, axis=axis, keepdims=keepdims, dtype=dtype, select_last_index=select_last_index, out=out, )
[docs]def argmax( self: ivy.Container, /, *, axis: Optional[int] = None, keepdims: bool = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, select_last_index: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.argmax. This method simply wraps the function, and so the docstring for ivy.argmax also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a numeric data type. axis axis along which to search. If None, the function must return the index of the maximum value of the flattened array. Deafult: ``None``. keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array. dtype Optional output dtype of the container. out If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. Returns ------- ret a container containing the indices of the maximum values across the specified axis. Examples -------- >>> a = ivy.array([[4., 0., -1.], [2., -3., 6]]) >>> b = ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> x = ivy.Container(a=a, b=b) >>> y = x.argmax(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[0], [2]]), b: ivy.array([[2], [0]]) } """ return self.static_argmax( self, axis=axis, keepdims=keepdims, dtype=dtype, select_last_index=select_last_index, out=out, )
[docs]def static_argmin( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: Optional[int] = None, keepdims: bool = False, output_dtype: Optional[Union[ivy.int32, ivy.int64]] = None, select_last_index: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.argmin. This method simply wraps the function, and so the docstring for ivy.argmin also applies to this method with minimal changes. Parameters ---------- x input array or container. Should have a numeric data type. axis axis along which to search. If None, the function must return the index of the minimum value of the flattened array. Default = None. keepdims if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False. output_dtype An optional output_dtype from: int32, int64. Defaults to int64. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the indices of the minimum values across the specified axis. Examples -------- >>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]),\ ... b=ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> y = ivy.Container.static_argmin(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[2], [1]]), b: ivy.array([[0], [0]]) } """ return ContainerBase.cont_multi_map_in_function( "argmin", x, axis=axis, keepdims=keepdims, output_dtype=output_dtype, select_last_index=select_last_index, out=out, )
[docs]def argmin( self: ivy.Container, /, *, axis: Optional[int] = None, keepdims: bool = False, output_dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, select_last_index: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.argmin. This method simply wraps the function, and so the docstring for ivy.argmin also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a numeric data type. axis axis along which to search. If None, the function must return the index of the minimum value of the flattened array. Default = None. keepdims if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False. output_dtype An optional output_dtype from: int32, int64. Defaults to int64. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the indices of the minimum values across the specified axis. Examples -------- Using :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([0., -1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.argmin() >>> print(y) { a:ivy.array(1), b:ivy.array(0) } >>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]),\ ... b=ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> y = x.argmin(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[2], [1]]), b: ivy.array([[0], [0]]) } """ return self.static_argmin( self, axis=axis, keepdims=keepdims, output_dtype=output_dtype, select_last_index=select_last_index, out=out, )
[docs]def static_nonzero( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, as_tuple: bool = True, size: Optional[int] = None, fill_value: Number = 0, ) -> ivy.Container: """ ivy.Container static method variant of ivy.nonzero. This method simply wraps the function, and so the docstring for ivy.nonzero also applies to this method with minimal changes. Parameters ---------- x input array or container. Should have a numeric data type. as_tuple if True, the output is returned as a tuple of indices, one for each dimension of the input, containing the indices of the true elements in that dimension. If False, the coordinates are returned in a (N, ndim) array, where N is the number of true elements. Default = True. size if specified, the function will return an array of shape (size, ndim). If the number of non-zero elements is fewer than size, the remaining elements will be filled with fill_value. Default = None. fill_value when size is specified and there are fewer than size number of elements, the remaining elements in the output array will be filled with fill_value. Default = 0. Returns ------- ret a container containing the indices of the nonzero values. """ return ContainerBase.cont_multi_map_in_function( "nonzero", x, as_tuple=as_tuple, size=size, fill_value=fill_value )
[docs]def nonzero( self: ivy.Container, /, *, as_tuple: bool = True, size: Optional[int] = None, fill_value: Number = 0, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.nonzero. This method simply wraps the function, and so the docstring for ivy.nonzero also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a numeric data type. as_tuple if True, the output is returned as a tuple of indices, one for each dimension of the input, containing the indices of the true elements in that dimension. If False, the coordinates are returned in a (N, ndim) array, where N is the number of true elements. Default = True. size if specified, the function will return an array of shape (size, ndim). If the number of non-zero elements is fewer than size, the remaining elements will be filled with fill_value. Default = None. fill_value when size is specified and there are fewer than size number of elements, the remaining elements in the output array will be filled with fill_value. Default = 0. Returns ------- ret a container containing the indices of the nonzero values. """ return self.static_nonzero( self, as_tuple=as_tuple, size=size, fill_value=fill_value )
[docs]def static_where( condition: Union[ivy.Container, ivy.Array, ivy.NativeArray], x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.where. This method simply wraps the function, and so the docstring for ivy.where also applies to this method with minimal changes. Parameters ---------- condition input array or container. Should have a boolean data type. x1 input array or container. Should have a numeric data type. x2 input array or container. Should have a numeric data type. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the values of x1 where condition is True, and x2 where condition is False. Examples -------- >>> x1 = ivy.Container(a=ivy.array([3, 1, 5]), b=ivy.array([2, 4, 6])) >>> x2 = ivy.Container(a=ivy.array([0, 7, 2]), b=ivy.array([3, 8, 5])) >>> res = ivy.Container.static_where((x1.a > x2.a), x1, x2) >>> print(res) { a: ivy.array([3, 7, 5]), b: ivy.array([2, 8, 6]) } """ return ContainerBase.cont_multi_map_in_function( "where", condition, x1, x2, out=out )
[docs]def where( self: ivy.Container, x1: Union[ivy.Container, ivy.Array, ivy.NativeArray], x2: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.where. This method simply wraps the function, and so the docstring for ivy.where also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a boolean data type. x1 input array or container. Should have a numeric data type. x2 input array or container. Should have a numeric data type. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the values of x1 where condition is True, and x2 where condition is False. Examples -------- >>> x1 = ivy.Container(a=ivy.array([3, 1, 5]), b=ivy.array([2, 4, 6])) >>> x2 = ivy.Container(a=ivy.array([0, 7, 2]), b=ivy.array([3, 8, 5])) >>> res = x1.where((x1.a > x2.a), x2) >>> print(res) { a: ivy.array([3, 7, 5]), b: ivy.array([2, 8, 6]) } """ return self.static_where(self, x1, x2, out=out)
[docs]def static_argwhere( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.argwhere. This method simply wraps the function, and so the docstring for ivy.argwhere also applies to this method with minimal changes. Parameters ---------- self Boolean array, for which indices are desired. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Indices for where the boolean array is True. Examples -------- Using :class:`ivy.Container` instance method >>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> res = ivy.Container.static_argwhere(x) >>> print(res) { a: ivy.array([[0], [1]]), b: ivy.array([[0], [1]]) } >>> x = ivy.Container(a=ivy.array([1, 0]), b=ivy.array([3, 4])) >>> res = ivy.Container.static_argwhere(x) >>> print(res) { a: ivy.array([[0]]), b: ivy.array([[0], [1]]) } """ return ContainerBase.cont_multi_map_in_function( "argwhere", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def argwhere( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ): """ ivy.Container instance method variant of ivy.argwhere. This method simply wraps the function, and so the docstring for ivy.argwhere also applies to this method with minimal changes. Parameters ---------- self Boolean array, for which indices are desired. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is False. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret Indices for where the boolean array is True. Examples -------- Using :class:`ivy.Container` instance method >>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> res = x.argwhere() >>> print(res) { a: ivy.array([[0], [1]]), b: ivy.array([[0], [1]]) } >>> x = ivy.Container(a=ivy.array([1, 0]), b=ivy.array([3, 4])) >>> res = x.argwhere() >>> print(res) { a: ivy.array([[0]]), b: ivy.array([[0], [1]]) } """ return self.static_argwhere( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.set # global from typing import Dict, List, Optional, Union # local from ivy.container.base import ContainerBase import ivy
[docs]def static_unique_all( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.unique_all. This method simply wraps the function, and so the docstring for ivy.unique_all also applies to this method with minimal changes. Parameters ---------- x input container. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A container of namedtuples ``(values, indices, inverse_indices, counts)``. The details can be found in the docstring for ivy.unique_all. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 3. , 2. , 1. , 0.]), ... b=ivy.array([1,2,1,3,4,1,3])) >>> y = ivy.Container.static_unique_all(x) >>> print(y) { a: [ values = ivy.array([0., 1., 2., 3.]), indices = ivy.array([0, 1, 3, 2]), inverse_indices = ivy.array([0, 1, 3, 2, 1, 0]), counts = ivy.array([2, 2, 1, 1]) ], b: [ values = ivy.array([1, 2, 3, 4]), indices = ivy.array([0, 1, 3, 4]), inverse_indices = ivy.array([0, 1, 0, 2, 3, 0, 2]), counts = ivy.array([3, 1, 2, 1]) ] } """ return ContainerBase.cont_multi_map_in_function( "unique_all", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def unique_all( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.unique_all. This method simply wraps the function, and so the docstring for ivy.unique_all also applies to this method with minimal changes. Parameters ---------- self input container. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret A container of namedtuples ``(values, indices, inverse_indices, counts)``. The details of each entry can be found in the docstring for ivy.unique_all. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 3. , 2. , 1. , 0.]), ... b=ivy.array([1,2,1,3,4,1,3])) >>> y = x.static_unique_all() >>> print(y) { a: [ values = ivy.array([0., 1., 2., 3.]), indices = ivy.array([0, 1, 3, 2]), inverse_indices = ivy.array([0, 1, 3, 2, 1, 0]), counts = ivy.array([2, 2, 1, 1]) ], b: [ values = ivy.array([1, 2, 3, 4]), indices = ivy.array([0, 1, 3, 4]), inverse_indices = ivy.array([0, 1, 0, 2, 3, 0, 2]), counts = ivy.array([3, 1, 2, 1]) ] } """ return self.static_unique_all( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_unique_counts( x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.unique_counts. This method simply wraps the function, and so the docstring for ivy.unique_counts also applies to this method with minimal changes. Parameters ---------- x input container. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a namedtuple ``(values, counts)`` whose - first element must have the field name ``values`` and must be an array containing the unique elements of ``x``. The array must have the same data type as ``x``. - second element must have the field name ``counts`` and must be an array containing the number of times each unique element occurs in ``x``. The returned array must have same shape as ``values`` and must have the default array index data type. Examples -------- >>> x = ivy.Container(a=ivy.array([0., 1., 3. , 2. , 1. , 0.]), ... b=ivy.array([1,2,1,3,4,1,3])) >>> y = ivy.Container.static_unique_counts(x) >>> print(y) { a:[values=ivy.array([0.,1.,2.,3.]),counts=ivy.array([2,2,1,1])], b:[values=ivy.array([1,2,3,4]),counts=ivy.array([3,1,2,1])] } """ return ContainerBase.cont_multi_map_in_function( "unique_counts", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def unique_counts( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.unique_counts. This method simply wraps the function, and so the docstring for ivy.unique_counts also applies to this method with minimal changes. Parameters ---------- self input container. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a namedtuple ``(values, counts)`` whose - first element must have the field name ``values`` and must be an array containing the unique elements of ``x``. The array must have the same data type as ``x``. - second element must have the field name ``counts`` and must be an array containing the number of times each unique element occurs in ``x``. The returned array must have same shape as ``values`` and must have the default array index data type. Examples -------- With :class:`ivy.Container` instance method: >>> x = ivy.Container(a=ivy.array([0., 1., 3. , 2. , 1. , 0.]), ... b=ivy.array([1,2,1,3,4,1,3])) >>> y = x.unique_counts() >>> print(y) { a:[values=ivy.array([0.,1.,2.,3.]),counts=ivy.array([2,2,1,1])], b:[values=ivy.array([1,2,3,4]),counts=ivy.array([3,1,2,1])]} """ return self.static_unique_counts( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def static_unique_values( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "unique_values", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def unique_values( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_unique_values( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_unique_inverse( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container static method variant of ivy.unique_inverse. This method simply wraps the function, and so the docstring for ivy.unique_inverse also applies to this method with minimal changes. Parameters ---------- x input container. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a namedtuple ``(values, inverse_indices)`` whose - first element must have the field name ``values`` and must be an array containing the unique elements of ``x``. The array must have the same data type as ``x``. - second element must have the field name ``inverse_indices`` and must be an array containing the indices of ``values`` that reconstruct ``x``. The array must have the same shape as ``x`` and must have the default array index data type. Examples -------- >>> x = ivy.Container(a=ivy.array([4.,8.,3.,5.,9.,4.]), ... b=ivy.array([7,6,4,5,6,3,2])) >>> y = ivy.Container.static_unique_inverse(x) >>> print(y) { a:[values=ivy.array([3.,4.,5.,8.,9.]),inverse_indices=ivy.array([1,3,0,2,4,1])], b:[values=ivy.array([2,3,4,5,6,7]),inverse_indices=ivy.array([5,4,2,3,4,1,0])] } """ return ContainerBase.cont_multi_map_in_function( "unique_inverse", x, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
[docs]def unique_inverse( self: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.unique_inverse. This method simply wraps the function, and so the docstring for ivy.unique_inverse also applies to this method with minimal changes. Parameters ---------- self input container. If ``x`` has more than one dimension, the function must flatten ``x`` and return the unique elements of the flattened array. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. Returns ------- ret a namedtuple ``(values, inverse_indices)`` whose - first element must have the field name ``values`` and must be an array containing the unique elements of ``x``. The array must have the same data type as ``x``. - second element must have the field name ``inverse_indices`` and must be an array containing the indices of ``values`` that reconstruct ``x``. The array must have the same shape as ``x`` and must have the default array index data type. Examples -------- >>> x = ivy.Container(a=ivy.array([4.,8.,3.,5.,9.,4.]), ... b=ivy.array([7,6,4,5,6,3,2])) >>> y = x.unique_inverse() >>> print(y) { a:[values=ivy.array([3.,4.,5.,8.,9.]),inverse_indices=ivy.array([1,3,0,2,4,1])], b:[values=ivy.array([2,3,4,5,6,7]),inverse_indices=ivy.array([5,4,2,3,4,1,0])] } """ return self.static_unique_inverse( self, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, )
#ivy.container.sorting # global from typing import Optional, List, Union, Dict # local from ivy.container.base import ContainerBase import ivy # ToDo: implement all methods here as public instance methods # noinspection PyMissingConstructor
[docs]def static_argsort( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: int = -1, descending: bool = False, stable: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.argsort. This method simply wraps the function, and so the docstring for ivy.argsort also applies to this method with minimal changes. Parameters ---------- x input array or container. Should have a numeric data type. axis axis along which to sort. If set to ``-1``, the function must sort along the last axis. Default: ``-1``. descending sort order. If ``True``, the returned indices sort ``x`` in descending order (by value). If ``False``, the returned indices sort ``x`` in ascending order (by value). Default: ``False``. stable sort stability. If ``True``, the returned indices must maintain the relative order of ``x`` values which compare as equal. If ``False``, the returned indices may or may not maintain the relative order of ``x`` values which compare as equal (i.e., the relative order of ``x`` values which compare as equal is implementation-dependent). Default: ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the index values of sorted array. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([7, 2, 1]), ... b=ivy.array([3, 2])) >>> y = ivy.Container.static_argsort(x, axis=-1, descending=True, stable=False) >>> print(y) { a: ivy.array([0, 1, 2]), b: ivy.array([0, 1]) } >>> x = ivy.Container(a=ivy.array([7, 2, 1]), ... b=ivy.array([[3, 2], [7, 0.2]])) >>> y = ivy.Container.static_argsort(x, axis=-1, descending=True, stable=False) >>> print(y) { a: ivy.array([0, 1, 2]), b: ivy.array([[0, 1]],[0, 1]]) } With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([2, 5, 1]), ... b=ivy.array([1, 5], [.2,.1])) >>> y = ivy.Container.static_argsort(x,axis=-1, descending=True, stable=False) >>> print(y) { a: ivy.array([2, 0, 1]), b: ivy.array([[1, 0],[0,1]]) } >>> x = ivy.Container(a=ivy.native_array([2, 5, 1]), ... b=ivy.array([1, 5], [.2,.1])) >>> y = ivy.Container.static_argsort(x, axis=-1, descending=True, stable=False) >>> print(y) { a: ivy.array([2, 0, 1]), b: ivy.array([[1, 0],[0,1]]) } """ return ContainerBase.cont_multi_map_in_function( "argsort", x, axis=axis, descending=descending, stable=stable, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def argsort( self: ivy.Container, /, *, axis: int = -1, descending: bool = False, stable: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.argsort. This method simply wraps the function, and so the docstring for ivy.argsort also applies to this method with minimal changes. Parameters ---------- self input array or container. Should have a numeric data type. axis axis along which to sort. If set to ``-1``, the function must sort along the last axis. Default: ``-1``. descending sort order. If ``True``, the returned indices sort ``x`` in descending order (by value). If ``False``, the returned indices sort ``x`` in ascending order (by value). Default: ``False``. stable sort stability. If ``True``, the returned indices must maintain the relative order of ``x`` values which compare as equal. If ``False``, the returned indices may or may not maintain the relative order of ``x`` values which compare as equal (i.e., the relative order of ``x`` values which compare as equal is implementation-dependent). Default: ``True``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container containing the index values of sorted array. The returned array must have a data type determined by :ref:`type-promotion`. Examples -------- >>> x = ivy.Container(a=ivy.array([7, 2, 1]), ... b=ivy.array([3, 2])) >>> y = x.argsort(axis=-1, descending=True, stable=False) >>> print(y) { a: ivy.array([0, 1, 2]), b: ivy.array([0, 1]) } """ return self.static_argsort( self, axis=axis, descending=descending, stable=stable, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sort( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: int = -1, descending: bool = False, stable: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.sort. This method simply wraps the function, and so the docstring for ivy.sort also applies to this method with minimal changes. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([5, 9, 0.2]), ... b=ivy.array([[8, 1], [5, 0.8]])) >>> y = ivy.Container.static_sort(x) >>> print(y) { a: ivy.array([0.2, 5., 9.]), b: ivy.array([[1., 8.], [0.8, 5.]]) } >>> x = ivy.Container(a=ivy.array([8, 0.5, 6]), ... b=ivy.array([[9, 0.7], [0.4, 0]])) >>> y = ivy.Container.static_sort(x) >>> print(y) { a: ivy.array([0.5, 6., 8.]), b: ivy.array([[0.7, 9.], [0., 0.4]]) } """ return ContainerBase.cont_multi_map_in_function( "sort", x, axis=axis, descending=descending, stable=stable, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sort( self: ivy.Container, /, *, axis: int = -1, descending: bool = False, stable: bool = True, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.sort. This method simply wraps the function, and so the docstring for ivy.sort also applies to this method with minimal changes. Examples -------- >>> x = ivy.Container(a=ivy.array([5, 9, 0.2]), ... b=ivy.array([8, 1])) >>> y = x.sort() >>> print(y) { a: ivy.array([0.2, 5., 9.]), b: ivy.array([1, 8]) } >>> x = ivy.Container(a=ivy.array([5, 9, 0.2]), ... b=ivy.array([[8, 1], [5, 0.8]])) >>> y = x.sort() >>> print(y) { a: ivy.array([0.2, 5., 9.]), b: ivy.array([[1., 8.], [0.8, 5.]]) } >>> x = ivy.Container(a=ivy.array([8, 0.5, 6]), ... b=ivy.array([[9, 0.7], [0.4, 0]])) >>> y = ivy.sort(x) >>> print(y) { a: ivy.array([0.5, 6., 8.]), b: ivy.array([[0.7, 9.],[0., 0.4]]) } >>> x = ivy.Container(a=ivy.native_array([8, 0.5, 6]), ... b=ivy.array([[9, 0.7], [0.4, 0]])) >>> y = ivy.sort(x) >>> print(y) { a: ivy.array([0.5, 6., 8.]), b: ivy.array([[0.7, 9.],[0., 0.4]]) } """ return self.static_sort( self, axis=axis, descending=descending, stable=stable, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_searchsorted( x1: Union[ivy.Array, ivy.NativeArray, ivy.Container], v: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, side="left", sorter=None, ret_dtype=ivy.int64, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.searchsorted. This method simply wraps the function, and so the docstring for ivy.searchsorted also applies to this method with minimal changes. """ return ContainerBase.cont_multi_map_in_function( "searchsorted", x1, v, side=side, sorter=sorter, ret_dtype=ret_dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def searchsorted( self: ivy.Container, v: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, side="left", sorter=None, ret_dtype=ivy.int64, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.searchsorted. This method simply wraps the function, and so the docstring for ivy.searchsorted also applies to this method with minimal changes. """ return self.static_searchsorted( self, v, side=side, sorter=sorter, ret_dtype=ret_dtype, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.statistical # global from typing import Optional, Union, List, Dict, Sequence # local import ivy from ivy.container.base import ContainerBase # ToDo: implement all methods here as public instance methods
[docs]def min( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.min. This method simply wraps the function, and so the docstring for ivy.min also applies to this method with minimal changes. Parameters ---------- x Input cotainer. Should have a real-valued data type. axis axis or axes along which minimum values must be computed. By default, the minimum value must be computed over the entire array. If a tuple of integers, minimum values must be computed over multiple axes. Default: ``None``. keepdims optional boolean, if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``. out optional output array, for writing the result to. Returns ------- ret if the minimum value was computed over the entire array, a zero-dimensional array containing the minimum value; otherwise, a non-zero-dimensional array containing the minimum values. The returned array must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >> > x = ivy.Container(a=ivy.array([1, 2, 3]), \ b=ivy.array([2, 3, 4])) >> > z = x.min() >> > print(z) { a: ivy.array(1), b: ivy.array(2) } >>> x = ivy.Container(a=ivy.array([[1, 2, 3],[-1,0,2]]), ... b=ivy.array([[2, 3, 4], [0, 1, 2]])) >>> z = x.min(axis=1) >>> print(z) { a:ivy.array([1,-1]), b:ivy.array([2,0]) } """ return self.cont_handle_inplace( self.cont_map( lambda x_, _: ivy.min(x_, axis=axis, keepdims=keepdims) if ivy.is_array(x_) else x_, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, ), out=out, )
[docs]def max( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.max. This method simply wraps the function, and so the docstring for ivy.max also applies to this method with minimal changes. Parameters ---------- x Input container. Should have a real-valued data type. axis axis or axes along which max values must be computed. By default, the maximum value must be computed over the entire array. If a tuple of integers, maximum values must be computed over multiple axes. Default: ``None``. keepdims optional boolean, if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``. out optional output array, for writing the result to. Returns ------- ret if the maximum value was computed over the entire array, a zero-dimensional array containing the maximum value; otherwise, a non-zero-dimensional array containing the maximum values. The returned array must have the same data type as ``x``. Examples -------- With :class:`ivy.Container` input: >> > x = ivy.Container(a=ivy.array([1, 2, 3]), \ b=ivy.array([2, 3, 4])) >> > z = x.max() >> > print(z) { a: ivy.array(3), b: ivy.array(4) } >>> x = ivy.Container(a=ivy.array([[1, 2, 3],[-1,0,2]]), ... b=ivy.array([[2, 3, 4], [0, 1, 2]])) >>> z = x.max(axis=1) >>> print(z) { a: ivy.array([3, 2]), b: ivy.array([4, 2]) } """ return self.cont_handle_inplace( self.cont_map( lambda x_, _: ivy.max(x_, axis=axis, keepdims=keepdims) if ivy.is_array(x_) else x_, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, ), out=out, )
[docs]def mean( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.mean. This method simply wraps the function, and so the docstring for ivy.mean also applies to this method with minimal changes. Parameters ---------- self input container. Should have a floating-point data type. axis axis or axes along which arithmetic means must be computed. By default, the mean must be computed over the entire array. If a Sequence of integers, arithmetic means must be computed over multiple axes. Default: ``None``. keepdims bool, if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret container, if the arithmetic mean was computed over the entire array, a zero-dimensional array containing the arithmetic mean; otherwise, a non-zero-dimensional array containing the arithmetic means. The returned array must have the same data type as ``self``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.mean() >>> print(y) { a: ivy.array(1.), b: ivy.array(4.) } >>> x = ivy.Container(a=ivy.array([0.1, 1.1]), b=ivy.array([0.1, 1.1, 2.1])) >>> y = x.mean(keepdims=True) >>> print(y) { a: ivy.array([0.60000002]), b: ivy.array([1.10000002]) } >>> x = ivy.Container(a=ivy.array([[0.1, 1.1]]), b=ivy.array([[2, 3]])) >>> y = x.mean(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[0.60000002]]), b: ivy.array([[2.5]]) } >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), b=ivy.array([1.1, 0.2, 1.4])) >>> x.mean(out=x) >>> print(x) { a: ivy.array(0.), b: ivy.array(0.9) } >>> x = ivy.Container(a=ivy.array([0., -1., 1.]), b=ivy.array([1., 1., 1.])) >>> y = ivy.Container(a=ivy.array(0.), b=ivy.array(0.)) >>> x.mean(out=y) >>> print(y) { a: ivy.array(0.), b: ivy.array(1.) } >>> x = ivy.Container(a=ivy.array([[0., 1., 2.], [3., 4., 5.]]), ... b=ivy.array([[3., 4., 5.], [6., 7., 8.]])) >>> x.mean(axis=0, out=x) >>> print(x) { a: ivy.array([1.5, 2.5, 3.5]), b: ivy.array([4.5, 5.5, 6.5]) } >>> x = ivy.Container(a=ivy.array([[1., 1., 1.], [2., 2., 2.]]), ... b=ivy.array([[3., 3., 3.], [4., 4., 4.]])) >>> y = ivy.mean(x, axis=1) >>> print(y) { a: ivy.array([1., 2.]), b: ivy.array([3., 4.]) } """ return self.cont_handle_inplace( self.cont_map( lambda x_, _: ivy.mean(x_, axis=axis, keepdims=keepdims) if ivy.is_array(x_) else x_, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, ), out=out, )
[docs]def var( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, correction: Union[int, float] = 0.0, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.var. This method simply wraps the function, and so the docstring for ivy.var also applies to this method with minimal changes. Parameters ---------- self input container. Should have a floating-point data type. axis axis or axes along which variances must be computed. By default, the variance must be computed over the entire array for each array in the input container. If a tuple of integers, variances must be computed over multiple axes. Default: ``None``. correction degrees of freedom adjustment. Setting this parameter to a value other than 0 has the effect of adjusting the divisor during the calculation of the variance according to N-c where N corresponds to the total number of elements over which the variance is computed and c corresponds to the provided degrees of freedom adjustment. When computing the variance of a population, setting this parameter to 0 is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample variance, setting this parameter to 1 is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). Default: ``0``. keepdims if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: ``False``. input array. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret a container contianing different arrays depends on parameters. see below for the types of arrays in the returned container if the variance was computed over the entire array, a zero-dimensional array containing the variance; otherwise, a non-zero-dimensional array containing the variances. The returned container must have the same data type as self. Examples -------- >>> x = ivy.Container(a=ivy.array([0.0, 1.0, 2.0]), ... b=ivy.array([3.0, 4.0, 5.0])) >>> y = x.var() >>> print(y) { a: ivy.array(0.6666667), b: ivy.array(0.6666667) } >>> x = ivy.Container(a=ivy.array([0.0, 1.0, 2.0]), ... b=ivy.array([3.0, 4.0, 5.0])) >>> y = ivy.Container(a=ivy.array(0.), b=ivy.array(0.)) >>> x.var(out=y) >>> print(y) { a: ivy.array(0.6666667), b: ivy.array(0.6666667) } >>> x = ivy.Container(a=ivy.array([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]]), ... b=ivy.array([[6.0, 7.0, 8.0], [9.0, 10.0, 11.0]])) >>> y = ivy.Container(a=ivy.array([0., 0., 0.]), b=ivy.array([0., 0., 0.])) >>> x.var(axis=0, out=y) >>> print(y) { a: ivy.array([2.25, 2.25, 2.25]), b: ivy.array([2.25, 2.25, 2.25]) } """ return self.cont_handle_inplace( self.cont_map( lambda x_, _: ivy.var( x_, axis=axis, correction=correction, keepdims=keepdims ) if ivy.is_array(x_) else x_, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, ), out=out, )
[docs]def static_var( x: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, correction: Union[int, float] = 0.0, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.var. This method simply wraps the function, and so the docstring for ivy.var also applies to this method with minimal changes. Parameters ---------- self input array. Should have a floating-point data type. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret if the variance was computed over the entire array, a zero-dimensional array containing the variance; otherwise, a non-zero-dimensional array containing the variances. The returned array must have the same data type as x. Examples -------- >>> x = ivy.Container(a=ivy.array([0.1, 0.2, 0.9]), ... b=ivy.array([0.7, 0.1, 0.9])) >>> y = ivy.Container.static_var(x) >>> print(y) { a:ivy.array(0.12666667), b:ivy.array(0.11555555) } """ return ContainerBase.cont_multi_map_in_function( "var", x, key_chains=key_chains, axis=axis, correction=correction, keepdims=keepdims, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_prod( x: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ): """ivy.Container static method variant of ivy.prod. This method simply wraps the function, and so the docstring for ivy.prod also applies to this method with minimal changes. Parameters ---------- x input container. Should have a floating-point data type. axis axis or axes along which products must be computed. By default, the product must be computed over the entire array. If a tuple of integers, products must be computed over multiple axes. Default: ``None``. keepdims bool, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: ``False``. dtype data type of the returned array. out optional output array, for writing the result to. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret container, if the product was computed over the entire array, a zero-dimensional array containing the product; otherwise, a non-zero-dimensional array containing the products. The returned array must have the same data type as ``self``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = ivy.Container.static_prod(x) >>> print(y) { a: ivy.array(0.), b: ivy.array(60.) } >>> x = ivy.Container(a=ivy.array([0.1, 1.1]), b=ivy.array([0.1, 1.1, 2.1])) >>> y = ivy.Container.static_prod(x, keepdims=True) >>> print(y) { a: ivy.array([0.11000001]), b: ivy.array([0.23100001]) } >>> x = ivy.Container(a=ivy.array([[2, 1]]), b=ivy.array([[2, 3]])) >>> y = ivy.Container.static_prod(x, axis=1, keepdims=True) >>> print(y) { a: ivy.array([[2]]), b: ivy.array([[6]]) } >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), b=ivy.array([1.1, 0.2, 1.4])) >>> ivy.Container.static_prod(x, out=x) >>> print(x) { a: ivy.array(0), b: ivy.array(0.30800003) } >>> x = ivy.Container(a=ivy.array([0., -1., 1.]), b=ivy.array([1., 1., 1.])) >>> y = ivy.Container(a=ivy.array(0.), b=ivy.array(0.)) >>> ivy.Container.static_prod(x, out=y) >>> print(y) { a: ivy.array(-0.), b: ivy.array(1.) } >>> x = ivy.Container(a=ivy.array([[0., 1., 2.], [3., 4., 5.]]), ... b=ivy.array([[3., 4., 5.], [6., 7., 8.]])) >>> ivy.Container.static_prod(x, axis=0, out=x) >>> print(x) { a: ivy.array([0., 4., 10.]), b: ivy.array([18., 28., 40.]) } >>> x = ivy.Container(a=ivy.array([[1., 1., 1.], [2., 2., 2.]]), ... b=ivy.array([[3., 3., 3.], [4., 4., 4.]])) >>> y = ivy.Container.static_prod(x, axis=1) >>> print(y) { a: ivy.array([1., 8.]), b: ivy.array([27., 64.]) } """ return ContainerBase.cont_multi_map_in_function( "prod", x, axis=axis, dtype=dtype, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def prod( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.prod. This method simply wraps the function, and so the docstring for ivy.prod also applies to this method with minimal changes. Parameters ---------- self input container. Should have a floating-point data type. axis axis or axes along which products must be computed. By default, the product must be computed over the entire array. If a tuple of integers, products must be computed over multiple axes. Default: ``None``. keepdims bool, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: ``False``. dtype data type of the returned array. out optional output array, for writing the result to. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret container, if the product was computed over the entire array, a zero-dimensional array containing the product; otherwise, a non-zero-dimensional array containing the products. The returned array must have the same data type as ``self``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.prod() >>> print(y) { a: ivy.array(0.), b: ivy.array(60.) } >>> x = ivy.Container(a=ivy.array([0.1, 1.1]), b=ivy.array([0.1, 1.1, 2.1])) >>> y = x.prod(keepdims=True) >>> print(y) { a: ivy.array([0.11000001]), b: ivy.array([0.23100001]) } >>> x = ivy.Container(a=ivy.array([[2, 1]]), b=ivy.array([[2, 3]])) >>> y = x.prod(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[2]]), b: ivy.array([[6]]) } >>> x = ivy.Container(a=ivy.array([-1, 0, 1]), b=ivy.array([1.1, 0.2, 1.4])) >>> x.prod(out=x) >>> print(x) { a: ivy.array(0), b: ivy.array(0.30800003) } >>> x = ivy.Container(a=ivy.array([0., -1., 1.]), b=ivy.array([1., 1., 1.])) >>> y = ivy.Container(a=ivy.array(0.), b=ivy.array(0.)) >>> x.prod(out=y) >>> print(y) { a: ivy.array(-0.), b: ivy.array(1.) } >>> x = ivy.Container(a=ivy.array([[0., 1., 2.], [3., 4., 5.]]), ... b=ivy.array([[3., 4., 5.], [6., 7., 8.]])) >>> x.prod(axis=0, out=x) >>> print(x) { a: ivy.array([0., 4., 10.]), b: ivy.array([18., 28., 40.]) } >>> x = ivy.Container(a=ivy.array([[1., 1., 1.], [2., 2., 2.]]), ... b=ivy.array([[3., 3., 3.], [4., 4., 4.]])) >>> y = x.prod(axis=1) >>> print(y) { a: ivy.array([1., 8.]), b: ivy.array([27., 64.]) } """ return self.static_prod( self, axis=axis, dtype=dtype, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_sum( x: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return ContainerBase.cont_multi_map_in_function( "sum", x, axis=axis, dtype=dtype, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def sum( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: return self.static_sum( self, axis=axis, dtype=dtype, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def std( self: ivy.Container, /, *, axis: Union[int, Sequence[int]] = None, correction: Union[int, float] = 0.0, keepdims: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ivy.Container instance method variant of ivy.std. This method simply wraps the function, and so the docstring for ivy.std also applies to this method with minimal changes. Parameters ---------- self input container. axis axis or axes along which standard deviation must be computed. By default, the product must be computed over the entire array. If a tuple of integers, products must be computed over multiple axes. Default: ``None``. correction degrees of freedom adjustment. Setting this parameter to a value other than ``0`` has the effect of adjusting the divisor during the calculation of the standard deviation according to ``N-c`` where ``N`` corresponds to the total number of elements over which the standard deviation is computed and ``c`` corresponds to the provided degrees of freedom adjustment. When computing the standard deviation of a population, setting this parameter to ``0`` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample standard deviation, setting this parameter to ``1`` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). Default: ``0``. keepdims bool, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: ``False``. out optional output array, for writing the result to. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret container, if the standard deviation was computed over the entire array, a zero-dimensional array containing the standard deviation; otherwise, a non-zero-dimensional array containing the respectve standard deviations. The returned array must have the same data type as ``self``. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([0., 2.]), b=ivy.array([-4., 5.])) >>> y = x.std() >>> print(y) { a: ivy.array(1.), b: ivy.array(4.5) } >>> x = ivy.Container(a=ivy.array([0.1, 1.1]), b=ivy.array([0.1, 1.1, 2.1])) >>> y = x.std(keepdims=True) >>> print(y) { a: ivy.array([0.5]), b: ivy.array([0.81649649]) } >>> x = ivy.Container(a=ivy.array([[2, 1]]), b=ivy.array([[2, -2]])) >>> y = x.std(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[0.5]]), b: ivy.array([[2.]]) } >>> x = ivy.Container(a=ivy.array([-1, 1, 1]), b=ivy.array([1.1, 0.2, 1.4])) >>> x.std(out=x) >>> print(x) { a: ivy.array(0.94280904), b: ivy.array(0.509902) } >>> x = ivy.Container(a=ivy.array([0., -2., 1.]), b=ivy.array([1., 1., 1.])) >>> y = ivy.Container(a=ivy.array(0.), b=ivy.array(0.)) >>> x.std(out=y) >>> print(y) { a: ivy.array(1.2472192), b: ivy.array(0.) } >>> x = ivy.Container(a=ivy.array([[-1., 1., 2.], [2., 2., 2.]]), ... b=ivy.array([[3., 0., -3.], [4., 1., 4.]])) >>> y = ivy.std(x, axis=1) >>> print(y) { a: ivy.array([1.2472192, 0.]), b: ivy.array([2.44948983, 1.41421354]) } """ return self.cont_handle_inplace( self.cont_map( lambda x_, _: ivy.std( x_, axis=axis, correction=correction, keepdims=keepdims ) if ivy.is_array(x_) else x_, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, ), out=out, )
[docs]def static_cumsum( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], axis: int = 0, exclusive: bool = False, reverse: bool = False, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cumsum. This method simply wraps the function, and so the docstring for ivy.cumsum also applies to this method with minimal changes. Parameters ---------- x Input array or container to apply cumsum. axis Axis along which the cumulative sum is computed. Default is ``0``. exclusive Whether to perform cumsum exclusively. Default is ``False``. reverse Whether to perform the cumsum from last to first element in the selected axis. Default is ``False`` (from first to last element) key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype Data type of the returned array. Default is ``None``. out Optional output container. Default is ``None``. Returns ------- ret Container whose leaves hold the result of applying cumsum at each original leaf arrays along the specified axis. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[1, 2, 3], [2, 4, 5]]), ... b=ivy.array([[4, 5, 6], [2, 3, 1 ]])) >>> y = ivy.Container.static_cumsum(x, axis=0) >>> print(y) { a: ivy.array([[1, 2, 3], [3, 6, 8]]), b: ivy.array([[4, 5, 6], [6, 8, 7]]) } >>> x = ivy.Container(a=ivy.array([[1, 3, 5]]), ... b=ivy.array([[3, 5, 7]])) >>> y = ivy.Container.static_cumsum(x, axis=0, ... exclusive=False, reverse=True, dtype='float32') >>> print(y) { a: ivy.array([[1., 3., 5.]]), b: ivy.array([[3., 5., 7.]]) } >>> x = ivy.Container(a=ivy.array([[1, 3, 4]]), ... b=ivy.array([[3, 5, 8], ... [5, 6, 5]]), ... c=ivy.array([[2, 4, 1], ... [3, 6, 9], ... [0, 2, 3]])) >>> y = ivy.Container(a = ivy.zeros((1, 3)), ... b = ivy.zeros((2, 3)), ... c = ivy.zeros((3,3))) >>> ivy.cumsum(x,axis=1,exclusive=True, reverse=False, out=y) >>> print(y) { a: ivy.array([[0, 1, 4]]), b: ivy.array([[0, 3, 8], [0, 5, 11]]), c: ivy.array([[0, 2, 6], [0, 3, 9], [0, 0, 2]]) } >>> x = ivy.Container(a=ivy.array([[1, 3, 4], [5, 7, 8], [9, 10, 11]]), ... b=ivy.array([[3, 4, 5], [4, 5, 6], [5, 6, 7]])) >>> y = ivy.Container(a= ivy.zeros((3, 3)), b= ivy.zeros((3, 3))) >>> ivy.Container.static_cumsum(x, axis=1, exclusive=True, reverse=True, out=y) >>> print(y) { a: ivy.array([[7, 4, 0], [15, 8, 0], [21, 11, 0]]), b: ivy.array([[9, 5, 0], [11, 6, 0], [13, 7, 0]]) } >>> x = ivy.Container(a=ivy.array([[1], ... [1]]), ... b=ivy.array([[6, 8, 7], ... [2, 0, 1]]), ... c=ivy.array([[1, 2], ... [3, 4], ... [6, 4]])) >>> ivy.Container.static_cumsum(x, axis=0, out=x) >>> print(x) { a: ivy.array([[1], [2]]), b: ivy.array([[6, 8, 7], [8, 8, 8]]), c: ivy.array([[1, 2], [4, 6], [10, 10]]) } """ return ContainerBase.cont_multi_map_in_function( "cumsum", x, axis=axis, exclusive=exclusive, reverse=reverse, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def cumsum( self: ivy.Container, axis: int = 0, exclusive: bool = False, reverse: bool = False, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.cumsum. This method simply wraps the function, and so the docstring for ivy.cumsum also applies to this method with minimal changes. Parameters ---------- self Input container to apply cumsum at leaves. axis Axis along which the cumulative sum is computed. Default is ``0``. exclusive Whether to perform cumsum exclusively. Default is ``False``. reverse Whether to perform the cumsum from last to first element in the selected axis. Default is ``False`` (from first to last element) key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype Data type of the returned array. Default is ``None``. out Optional output container. Default is ``None``. Returns ------- ret Container whose leaves hold the result of applying cumsum at each original leaf arrays along the specified axis. Examples -------- With :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([[1, 2, 3], ... [2, 4, 5]]), ... b=ivy.array([[4, 5, 6], ... [2, 3, 1 ]])) >>> y = x.cumsum(axis=0, dtype='float64') >>> print(y) { a: ivy.array([[1., 2., 3.], [3., 6., 8.]]), b: ivy.array([[4., 5., 6.], [6., 8., 7.]]) } >>> x = ivy.Container(a=ivy.array([[1, 3, 4], ... [5, 7, 8], ... [9, 10, 11]]), ... b=ivy.array([[3, 4, 5], ... [4, 5, 6], ... [5, 6, 7]])) >>> y = ivy.Container(a= ivy.zeros((3, 3)), b= ivy.zeros((3, 3))) >>> x.cumsum(axis=1, exclusive=False, reverse=True, out=y) >>> print(y) { a: ivy.array([[8, 7, 4], [20, 15, 8], [30, 21, 11]]), b: ivy.array([[12, 9, 5], [15, 11, 6], [18, 13, 7]]) } >>> x = ivy.Container(a=ivy.array([[1, 3, 4]]), ... b=ivy.array([[3, 5, 8], ... [5, 6, 5]]), ... c=ivy.array([[2, 4, 1], ... [3, 6, 9], ... [0, 2, 3]])) >>> y = ivy.Container(a = ivy.zeros((1, 3)), ... b = ivy.zeros((2, 3)), ... c = ivy.zeros((3,3))) >>> x.cumsum(axis=1,exclusive=True, reverse=False, out=y) >>> print(y) { a: ivy.array([[0, 1, 4]]), b: ivy.array([[0, 3, 8], [0, 5, 11]]), c: ivy.array([[0, 2, 6], [0, 3, 9], [0, 0, 2]]) } >>> x = ivy.Container(a=ivy.array([[0, 3, 2], ... [5, 10, 2], ... [1, 10, 1]]), ... b=ivy.array([[2, 4, 5], ... [4, 5, 5], ... [0, 1, 3]])) >>> y = x.cumsum(axis=1,exclusive=True, reverse=True, dtype='int64') >>> print(y) { a: ivy.array([[5, 2, 0], [12, 2, 0], [11, 1, 0]]), b: ivy.array([[9, 5, 0], [10, 5, 0], [4, 3, 0]]) } >>> x = ivy.Container(a=ivy.array([[0], ... [5]]), ... b=ivy.array([[6, 8, 7], ... [4, 2, 3]]), ... c=ivy.array([[1, 2], ... [3, 4], ... [6, 4]])) >>> x.cumsum(axis=0, out=x) >>> print(x) { a: ivy.array([[0], [5]]), b: ivy.array([[6, 8, 7], [10, 10, 10]]), c: ivy.array([[1, 2], [4, 6], [10, 10]]) } """ return self.static_cumsum( self, axis=axis, exclusive=exclusive, reverse=reverse, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def static_cumprod( x: Union[ivy.Container, ivy.Array, ivy.NativeArray], /, *, axis: int = 0, exclusive: bool = False, reverse: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.cumprod. This method simply wraps the function, and so the docstring for ivy.cumprod also applies to this method with minimal changes. Parameters ---------- x Input array or container to cumprod. axis Axis to cumprod along. Default is ``0``. exclusive Whether to exclude the first element of the input array. Default is ``False``. reverse Whether to perform the cumprod from last to first element in the selected axis. Default is ``False`` (from first to last element) key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype Data type of the returned array. Default is ``None``. out Optional output container. Default is ``None``. Returns ------- ret Containers with arrays cumprod at leaves along specified axis. Examples -------- With one :class:`ivy.Container` input: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([4, 5, 6])) >>> y = ivy.Container.static_cumprod(x, axis=0) >>> print(y) { a: ivy.array([1, 2, 6]), b: ivy.array([4, 20, 120]) } >>> x = ivy.Container(a=ivy.array([[2, 3], [5, 7], [11, 13]]), b=ivy.array([[3, 4], [4, 5], [5, 6]])) >>> y = ivy.Container(a = ivy.zeros((3, 2)), b = ivy.zeros((3, 2))) >>> ivy.Container.static_cumprod(x, axis=1, exclusive=True, out=y) >>> print(y) { a: ivy.array([[1, 2], [1, 5], [1, 11]]), b: ivy.array([[1, 3], [1, 4], [1, 5]]) } """ return ContainerBase.cont_multi_map_in_function( "cumprod", x, axis=axis, exclusive=exclusive, reverse=reverse, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def cumprod( self: ivy.Container, /, *, axis: int = 0, exclusive: bool = False, reverse: bool = False, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype]] = None, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.cumprod. This method simply wraps the function, and so the docstring for ivy.cumprod also applies to this method with minimal changes. Parameters ---------- self Input container to cumprod at leaves. axis Axis along which the cumulative product is computed. Default is ``0``. exclusive Whether to exclude the first element of the input array. Default is ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. dtype Data type of the returned array. Default is ``None``. out Optional output container. Default is ``None``. Returns ------- ret Containers with arrays cumprod at leaves along specified axis. Examples -------- With one :class:`ivy.Container` instances: >>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([4, 5, 6])) >>> y = x.cumprod(axis=0) >>> print(y) { a: ivy.array([1, 2, 6]), b: ivy.array([4, 20, 120]) } >>> x = ivy.Container(a=ivy.array([[2, 3], [5, 7], [11, 13]]), b=ivy.array([[3, 4], [4, 5], [5, 6]])) >>> y = ivy.Container(a = ivy.zeros((3, 2)), b = ivy.zeros((3, 2))) >>> x.cumprod(axis=1, exclusive=True, out=y) { a: ivy.array([[1, 2], [1, 5], [1, 11]]), b: ivy.array([[1, 3], [1, 4], [1, 5]]) } """ return self.static_cumprod( self, axis=axis, exclusive=exclusive, reverse=reverse, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, dtype=dtype, out=out, )
[docs]def einsum( self: ivy.Container, equation: str, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, *, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ >>> x = ivy.Container(a=ivy.array([[0, 1, 0],[1, 1, 0],[1, 1, 1]]), ... b=ivy.array([[0, 1, 2],[4, 5, 6],[8, 9, 10]])) >>> y = x.einsum('ii') >>> print(y) { a: ivy.array(2), b: ivy.array(15) } """ return self.cont_handle_inplace( self.cont_map( lambda x_, _: ivy.einsum(equation, x_) if ivy.is_array(x_) else x_, key_chains, to_apply, prune_unapplied, map_sequences, ), out=out, )
#ivy.container.utility # global from typing import Optional, Union, Dict, Sequence # local import ivy from ivy.container.base import ContainerBase # noinspection PyMissingConstructor
[docs]def static_all( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: Optional[Union[int, Sequence[int], ivy.Container]] = None, keepdims: Union[bool, ivy.Container] = False, key_chains: Optional[Union[Sequence[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.all. This method simply wraps the function, and so the docstring for ivy.all also applies to this method with minimal changes. Parameters ---------- x input container. axis axis or axes along which to perform a logical AND reduction. By default, a logical AND reduction must be performed over the entire array. If a tuple of integers, logical AND reductions must be performed over multiple axes. A valid ``axis`` must be an integer on the interval ``[-N, N)``, where ``N`` is the rank(number of dimensions) of ``self``. If an ``axis`` is specified as a negative integer, the function must determine the axis along which to perform a reduction by counting backward from the last dimension (where ``-1`` refers to the last dimension). If provided an invalid ``axis``, the function must raise an exception. Default ``None``. keepdims If ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes(dimensions) must not be included in the result. Default: ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret if a logical AND reduction was performed over the entire array, the returned container must be a zero-dimensional array containing the test result; otherwise, the returned container must be a non-zero-dimensional array containing the test results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([0, 1, 1])) >>> y = ivy.Container.static_all(x) >>> print(y) { a: ivy.array(False), b: ivy.array(False) } """ return ContainerBase.cont_multi_map_in_function( "all", x, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def all( self: ivy.Container, /, *, axis: Optional[Union[int, Sequence[int], ivy.Container]] = None, keepdims: Union[bool, ivy.Container] = False, key_chains: Optional[Union[Sequence[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.all. This method simply wraps the function, and so the docstring for ivy.all also applies to this method with minimal changes. Parameters ---------- self input container. axis axis or axes along which to perform a logical AND reduction. By default, a logical AND reduction must be performed over the entire array. If a tuple of integers, logical AND reductions must be performed over multiple axes. A valid ``axis`` must be an integer on the interval ``[-N, N)``, where ``N`` is the rank(number of dimensions) of ``self``. If an ``axis`` is specified as a negative integer, the function must determine the axis along which to perform a reduction by counting backward from the last dimension (where ``-1`` refers to the last dimension). If provided an invalid ``axis``, the function must raise an exception. Default ``None``. keepdims If ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes(dimensions) must not be included in the result. Default: ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output container, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret if a logical AND reduction was performed over the entire array, the returned container must be a zero-dimensional array containing the test result; otherwise, the returned container must have non-zero-dimensional arrays containing the test results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([0, 1, 1])) >>> y = x.all() >>> print(y) { a: ivy.array(False), b: ivy.array(False) } """ return self.static_all( self, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def static_any( x: Union[ivy.Array, ivy.NativeArray, ivy.Container], /, *, axis: Optional[Union[int, Sequence[int], ivy.Container]] = None, keepdims: Union[bool, ivy.Container] = False, key_chains: Optional[Union[Sequence[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container static method variant of ivy.any. This method simply wraps the function, and so the docstring for ivy.any also applies to this method with minimal changes. Parameters ---------- x input container. axis axis or axes along which to perform a logical OR reduction. By default, a logical OR reduction must be performed over the entire array. If a tuple of integers, logical OR reductions must be performed over multiple axes. A valid ``axis`` must be an integer on the interval ``[-N, N)``, where ``N`` is the rank(number of dimensions) of ``self``. If an ``axis`` is specified as a negative integer, the function must determine the axis along which to perform a reduction by counting backward from the last dimension (where ``-1`` refers to the last dimension). If provided an invalid ``axis``, the function must raise an exception. Default: ``None``. keepdims If ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes(dimensions) must not be included in the result. Default: ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret if a logical OR reduction was performed over the entire array, the returned container must be a zero-dimensional array containing the test result; otherwise, the returned container must have non-zero-dimensional arrays containing the test results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([0, 0, 0])) >>> y = ivy.Container.static_any(x) >>> print(y) { a: ivy.array(True), b: ivy.array(False) } """ return ContainerBase.cont_multi_map_in_function( "any", x, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
[docs]def any( self: ivy.Container, /, *, axis: Optional[Union[int, Sequence[int], ivy.Container]] = None, keepdims: Union[bool, ivy.Container] = False, key_chains: Optional[Union[Sequence[str], Dict[str, str]]] = None, to_apply: bool = True, prune_unapplied: bool = False, map_sequences: bool = False, out: Optional[ivy.Container] = None, ) -> ivy.Container: """ ivy.Container instance method variant of ivy.any. This method simply wraps the function, and so the docstring for ivy.any also applies to this method with minimal changes. Parameters ---------- self input container. axis axis or axes along which to perform a logical OR reduction. By default, a logical OR reduction must be performed over the entire array. If a tuple of integers, logical OR reductions must be performed over multiple axes. A valid ``axis`` must be an integer on the interval ``[-N, N)``, where ``N`` is the rank(number of dimensions) of ``self``. If an ``axis`` is specified as a negative integer, the function must determine the axis along which to perform a reduction by counting backward from the last dimension (where ``-1`` refers to the last dimension). If provided an invalid ``axis``, the function must raise an exception. Default: ``None``. keepdims If ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes(dimensions) must not be included in the result. Default: ``False``. key_chains The key-chains to apply or not apply the method to. Default is ``None``. to_apply If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is ``True``. prune_unapplied Whether to prune key_chains for which the function was not applied. Default is ``False``. map_sequences Whether to also map method to sequences (lists, tuples). Default is ``False``. out optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Returns ------- ret if a logical OR reduction was performed over the entire array, the returned container must be a zero-dimensional array containing the test result; otherwise, the returned container must have non-zero-dimensional arrays containing the test results. The returned container must have a data type of ``bool``. Examples -------- >>> x = ivy.Container(a=ivy.array([0, 1, 2]), b=ivy.array([0, 0, 0])) >>> y = x.any() >>> print(y) { a: ivy.array(True), b: ivy.array(False) } """ return self.static_any( self, axis=axis, keepdims=keepdims, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, )
#ivy.container.wrapping # local import ivy # global from typing import Callable, Type, List, Iterable, Optional from types import ModuleType TO_IGNORE = ["is_ivy_array", "is_native_array", "is_array", "shape"] def _wrap_function(function_name: str, static: bool) -> Callable: """Wraps the function called `function_name`. Parameters ---------- function_name the name of the function e.g. "abs", "mean" etc. static whether the function being wrapped will be added as a static method. Returns ------- new_function the wrapped function. """ def new_function( *args, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out: Optional[ivy.Container] = None, **kwargs ): function = ivy.__dict__[function_name] data_idx = function.array_spec[0] if ( not (data_idx[0][0] == 0 and len(data_idx[0]) == 1) and args and ivy.is_ivy_container(args[0]) and not static ): # if the method has been called as an instance method, and self should not # be the first positional arg, then we need to re-arrange and place self # in the correct location in the args or kwargs self = args[0] args = args[1:] if len(args) > data_idx[0][0]: args = ivy.copy_nest(args, to_mutable=True) data_idx = [data_idx[0][0]] + [ 0 if idx is int else idx for idx in data_idx[1:] ] ivy.insert_into_nest_at_index(args, data_idx, self) else: kwargs = ivy.copy_nest(kwargs, to_mutable=True) data_idx = [data_idx[0][1]] + [ 0 if idx is int else idx for idx in data_idx[1:] ] ivy.insert_into_nest_at_index(kwargs, data_idx, self) # return function multi-mapped across the corresponding leaves of the containers return ivy.ContainerBase.cont_multi_map_in_function( function_name, *args, key_chains=key_chains, to_apply=to_apply, prune_unapplied=prune_unapplied, map_sequences=map_sequences, out=out, **kwargs ) return new_function def add_ivy_container_instance_methods( cls: Type[ivy.Container], modules: List[ModuleType], static: bool = False, to_ignore: Iterable = (), ): """Loop over all ivy modules such as activations, general, etc. and add the module functions to ivy container as instance methods using _wrap_function. Parameters ---------- cls the class we want to add the instance methods to. modules the modules to loop over: activations, general etc. static whether the function should be added as a static method. to_ignore any functions we don't want to add an instance method for. Examples -------- As shown, `add_ivy_container_instance_methods` adds all the appropriate functions from the statistical module as instance methods to our toy `ContainerExample` class: >>> from ivy.functional.ivy import statistical >>> class ContainerExample: ... pass >>> ivy.add_ivy_container_instance_methods(ContainerExample, [statistical]) >>> print(hasattr(ContainerExample, "mean"), hasattr(ContainerExample, "var")) True True """ pass